mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
BUG/MINOR: fd/threads: properly lock the FD before adding it to the fd cache.
It was believed that it was useless to lock the "prev" field when adding a FD. However, if there's only one element in the FD cache, and that element removes itself from the fd cache, and another FD is added before the first add completed, there's a risk of losing elements. To prevent that, lock the "prev" field, so that such a removal will wait until the add completed.
This commit is contained in:
parent
58aa5ccd76
commit
1ff9104117
3
src/fd.c
3
src/fd.c
@ -198,7 +198,7 @@ void fd_add_to_fd_list(volatile struct fdlist *list, int fd)
|
||||
last = list->last;
|
||||
old = -1;
|
||||
|
||||
fdtab[fd].cache.prev = last;
|
||||
fdtab[fd].cache.prev = -2;
|
||||
/* Make sure the "prev" store is visible before we update the last entry */
|
||||
__ha_barrier_store();
|
||||
|
||||
@ -224,6 +224,7 @@ void fd_add_to_fd_list(volatile struct fdlist *list, int fd)
|
||||
/* since we're alone at the end of the list and still locked(-2),
|
||||
* we know noone tried to add past us. Mark the end of list.
|
||||
*/
|
||||
fdtab[fd].cache.prev = last;
|
||||
fdtab[fd].cache.next = -1;
|
||||
__ha_barrier_store();
|
||||
done:
|
||||
|
Loading…
Reference in New Issue
Block a user