MEDIUM: fd: Wait if locked in fd_grab_tgid() and fd_take_tgid().

Wait while the tgid is locked in fd_grab_tgid() and fd_take_tgid().
As that lock is barely used, it should have no impact.
This commit is contained in:
Olivier Houchard 2025-01-29 16:51:40 +01:00 committed by Olivier Houchard
parent 814b5dfe30
commit 52b97ff8dd

View file

@ -373,6 +373,10 @@ static inline uint fd_take_tgid(int fd)
uint old;
old = _HA_ATOMIC_FETCH_ADD(&fdtab[fd].refc_tgid, 0x10000) & 0xffff;
while (old & 0x8000) {
old = _HA_ATOMIC_LOAD(&fdtab[fd].refc_tgid) & 0xffff;
__ha_cpu_relax();
}
if (likely(old))
return old;
HA_ATOMIC_SUB(&fdtab[fd].refc_tgid, 0x10000);
@ -398,6 +402,11 @@ static inline uint fd_grab_tgid(int fd, uint desired_tgid)
uint old;
old = _HA_ATOMIC_FETCH_ADD(&fdtab[fd].refc_tgid, 0x10000) & 0xffff;
/* If the tgid is locked, wait until it no longer is */
while (old & 0x8000) {
old = _HA_ATOMIC_LOAD(&fdtab[fd].refc_tgid) & 0xffff;
__ha_cpu_relax();
}
if (likely(old == desired_tgid))
return 1;
HA_ATOMIC_SUB(&fdtab[fd].refc_tgid, 0x10000);