]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stick-tables: remove a few unneeded tests for use_wrlock
authorWilly Tarreau <w@1wt.eu>
Thu, 23 May 2024 18:24:35 +0000 (20:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 24 May 2024 09:52:19 +0000 (11:52 +0200)
Due to the code in stktable_touch_with_exp() being the same as in other
functions previously made around a loop trying first to upgrade a read
lock then to fall back to a direct write lock, there remains a confusing
construct with multiple tests on use_wrlock that is obviously zero when
tested. Let's remove them since the value is known and the loop does not
exist anymore.

src/stick_table.c

index 00f300f0fe54fef60c3ea22b4504deb13d01481d..00049d1c3197fc98a566738b5eb18ecfa3b10fae 100644 (file)
@@ -572,25 +572,14 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local,
 
        /* If sync is enabled */
        if (t->sync_task) {
-               /* We'll need to reliably check that the entry is in the tree.
-                * It's only inserted/deleted using a write lock so a read lock
-                * is sufficient to verify this. We may then need to upgrade it
-                * to perform an update (which is rare under load), and if the
-                * upgrade fails, we'll try again with a write lock directly.
-                */
-               if (use_wrlock)
-                       HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
-
                if (local) {
                        /* Check if this entry is not in the tree or not
                         * scheduled for at least one peer.
                         */
                        if (!ts->upd.node.leaf_p || _HA_ATOMIC_LOAD(&ts->seen)) {
-                               /* Time to upgrade the read lock to write lock if needed */
-                               if (!use_wrlock) {
-                                       HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
-                                       use_wrlock = 1;
-                               }
+                               /* Time to upgrade the read lock to write lock */
+                               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                               use_wrlock = 1;
 
                                /* here we're write-locked */
 
@@ -619,10 +608,8 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local,
                         */
                        if (!ts->upd.node.leaf_p) {
                                /* Time to upgrade the read lock to write lock if needed */
-                               if (!use_wrlock) {
-                                       HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
-                                       use_wrlock = 1;
-                               }
+                               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                               use_wrlock = 1;
 
                                /* here we're write-locked */
                                if (!ts->upd.node.leaf_p) {