diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index 094c0e81c..2c5e7a223 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 68095260c..a1cc03c0e 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);