mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-21 06:06:59 -04:00
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:
parent
814b5dfe30
commit
52b97ff8dd
1 changed files with 9 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue