From: Willy Tarreau Date: Thu, 23 May 2024 18:24:35 +0000 (+0200) Subject: CLEANUP: stick-tables: remove a few unneeded tests for use_wrlock X-Git-Tag: v3.0-dev13~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8580f9db20ffe070c577eec32d3316dd2f5027ab;p=thirdparty%2Fhaproxy.git CLEANUP: stick-tables: remove a few unneeded tests for use_wrlock 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. --- diff --git a/src/stick_table.c b/src/stick_table.c index 00f300f0fe..00049d1c31 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -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) {