]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: fd: make fd_insert/fd_delete atomically update fd.tgid
authorWilly Tarreau <w@1wt.eu>
Thu, 7 Jul 2022 13:05:55 +0000 (15:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Jul 2022 18:16:30 +0000 (20:16 +0200)
commitddedc1662487600d5124cb6d4972396438b9953c
treefe9f9f771d26dbd1585a74c6674dafe62721f2b9
parent27a32455994993f865aecd5c9b551bc79db441c5
MEDIUM: fd: make fd_insert/fd_delete atomically update fd.tgid

These functions need to set/reset the FD's tgid but when they're called
there may still be wakeups on other threads that discover late updates
and have to touch the tgid at the same time. As such, it is not possible
to just read/write the tgid there. It must only be done using operations
that are compatible with what other threads may be doing.

As we're using inc/dec on the refcount, it's safe to AND the area to zero
the lower part when resetting the value. However, in order to set the
value, there's no other choice but fd_claim_tgid() which will assign it
only if possible (via a CAS). This is convenient in the end because it
protects the FD's masks from being modified by late threads, so while
we hold this refcount we can safely reset the thread_mask and a few other
elements. A debug test for non-null masks was added to fd_insert() as it
must not be possible to face this situation thanks to the protection
offered by the tgid.
include/haproxy/fd.h
src/fd.c