MEDIUM: threads/freq_ctr: Make the frequency counters thread-safe
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Oct 2017 07:49:09 +0000 (09:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 12:58:32 +0000 (13:58 +0100)
commit94b712337d40c6b5bdf54c18025af1caf06ca7ac
tree7909f1fdcc05475f9575ff450356086a2c949c32
parentb5997f740b21ebb197e10a0f2fe9dc13163e1772
MEDIUM: threads/freq_ctr: Make the frequency counters thread-safe

When a frequency counter must be updated, we use the curr_sec/curr_tick fields
as a lock, by setting the MSB to 1 in a compare-and-swap to lock and by reseting
it to unlock. And when we need to read it, we loop until the counter is
unlocked. This way, the frequency counters are thread-safe without any external
lock. It is important to avoid increasing the size of many structures (global,
proxy, server, stick_table).
include/proto/freq_ctr.h
src/freq_ctr.c