From: Willy Tarreau Date: Mon, 5 Feb 2018 16:52:24 +0000 (+0100) Subject: MINOR: fd: reorder fd_add_to_fd_list() X-Git-Tag: v1.9-dev1~435 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11559a7530931b7e58852e2ee2b576538e8f46fd;p=thirdparty%2Fhaproxy.git MINOR: fd: reorder fd_add_to_fd_list() The function was cleaned up a bit from duplicated parts inherited from the initial attempt at getting it to work. It's a bit smaller and cleaner this way. --- diff --git a/src/fd.c b/src/fd.c index 06fd690539..87db0e96d2 100644 --- a/src/fd.c +++ b/src/fd.c @@ -191,50 +191,39 @@ redo_next: if (!HA_ATOMIC_CAS(&fdtab[fd].cache.next, &next, -2)) goto redo_next; __ha_barrier_store(); + + new = fd; redo_last: /* First, insert in the linked list */ last = list->last; old = -1; - new = fd; - if (unlikely(last == -1)) { - /* list is empty, try to add ourselves alone so that list->last=fd */ - fdtab[fd].cache.prev = last; + fdtab[fd].cache.prev = last; + /* Make sure the "prev" store is visible before we update the last entry */ + __ha_barrier_store(); - /* Make sure the "prev" store is visible before we update the last entry */ - __ha_barrier_store(); + if (unlikely(last == -1)) { + /* list is empty, try to add ourselves alone so that list->last=fd */ if (unlikely(!HA_ATOMIC_CAS(&list->last, &old, new))) goto redo_last; /* list->first was necessary -1, we're guaranteed to be alone here */ list->first = 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.next = -1; - goto done; /* We're done ! */ } else { - /* non-empty list, add past the tail */ - do { - new = fd; - old = -1; - fdtab[fd].cache.prev = last; - - __ha_barrier_store(); - - /* adding ourselves past the last element - * The CAS will only succeed if its next is -1, - * which means it's in the cache, and the last element. - */ - if (likely(HA_ATOMIC_CAS(&fdtab[last].cache.next, &old, new))) - break; + /* adding ourselves past the last element + * The CAS will only succeed if its next is -1, + * which means it's in the cache, and the last element. + */ + if (unlikely(!HA_ATOMIC_CAS(&fdtab[last].cache.next, &old, new))) goto redo_last; - } while (1); + + /* Then, update the last entry */ + list->last = fd; } - /* Then, update the last entry */ - list->last = fd; __ha_barrier_store(); + /* 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.next = -1; __ha_barrier_store(); done: