From: Willy Tarreau Date: Wed, 24 Apr 2024 06:19:20 +0000 (+0200) Subject: BUILD: stick-tables: silence build warnings when threads are disabled X-Git-Tag: v3.0-dev9~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=19f8762a986bfe4508d687f428d1b758f96ac2ec;p=thirdparty%2Fhaproxy.git BUILD: stick-tables: silence build warnings when threads are disabled 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. --- diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index 094c0e81c4..2c5e7a223e 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -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); diff --git a/src/stick_table.c b/src/stick_table.c index 68095260cd..a1cc03c0ec 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -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);