]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: reorder fd_add_to_fd_list()
authorWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2018 16:52:24 +0000 (17:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Feb 2018 18:45:41 +0000 (19:45 +0100)
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.

src/fd.c

index 06fd690539c1a28572da0e91330a698a4ce869ac..87db0e96d22c7113f8ad901e08fb6eb97794c18d 100644 (file)
--- 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: