]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: stick-tables: silence build warnings when threads are disabled
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 06:19:20 +0000 (08:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 06:23:56 +0000 (08:23 +0200)
Since 3.0-dev7 with commit 1a088da7c2 ("MAJOR: stktable: split the keys
across multiple shards to reduce contention"), building without threads
yields a warning about the shard not being used. This is because the
locks API does nothing of its arguments, which is the only place where
the shard is being used. We cannot modify the lock API to pretend to
consume its argument because quite often it's not even instantiated.
Let's just pretend we consume shard using an explict ALREADY_CHECKED()
statement instead. While we're at it, let's make sure that XXH32() is
not called when there is a single bucket!

No backport is needed.

include/haproxy/stick_table.h
src/stick_table.c

index 094c0e81c47281d50f1d75b00fabe37540bbe07c..2c5e7a223eb34d901c81e0b5e7f2352ef02464de 100644 (file)
@@ -199,7 +199,11 @@ static inline void *stktable_data_ptr_idx(struct stktable *t, struct stksess *ts
  */
 static inline uint stktable_calc_shard_num(const struct stktable *t, const void *key, size_t len)
 {
+#if CONFIG_HAP_TBL_BUCKETS > 1
        return XXH32(key, len, t->hash_seed) % CONFIG_HAP_TBL_BUCKETS;
+#else
+       return 0;
+#endif
 }
 
 /* kill an entry if it's expired and its ref_cnt is zero */
@@ -227,6 +231,9 @@ static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *t
 
                shard = stktable_calc_shard_num(t, ts->key.key, len);
 
+               /* make the compiler happy when shard is not used without threads */
+               ALREADY_CHECKED(shard);
+
                HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
                __stksess_kill_if_expired(t, ts);
                HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
index 68095260cdafabba512421632d54a79e1a151122..a1cc03c0ec101884f4f7feef18ef8581f1175974 100644 (file)
@@ -127,6 +127,9 @@ void stksess_free(struct stktable *t, struct stksess *ts)
 
        shard = stktable_calc_shard_num(t, ts->key.key, len);
 
+       /* make the compiler happy when shard is not used without threads */
+       ALREADY_CHECKED(shard);
+
        HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
        __stksess_free(t, ts);
        HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
@@ -173,6 +176,9 @@ int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt)
 
        shard = stktable_calc_shard_num(t, ts->key.key, len);
 
+       /* make the compiler happy when shard is not used without threads */
+       ALREADY_CHECKED(shard);
+
        HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
        ret = __stksess_kill(t, ts);
        HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);