Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/include/linux linux/llist.h: Various f...



details:   https://anonhg.NetBSD.org/src/rev/b7d54b803125
branches:  trunk
changeset: 1028658:b7d54b803125
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:36:48 2021 +0000

description:
linux/llist.h: Various fixups.

diffstat:

 sys/external/bsd/drm2/include/linux/llist.h |  48 ++++++++++++++++++----------
 1 files changed, 30 insertions(+), 18 deletions(-)

diffs (106 lines):

diff -r 30487eb7a3a0 -r b7d54b803125 sys/external/bsd/drm2/include/linux/llist.h
--- a/sys/external/bsd/drm2/include/linux/llist.h       Sun Dec 19 11:36:41 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/llist.h       Sun Dec 19 11:36:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: llist.h,v 1.3 2021/12/19 01:26:05 riastradh Exp $      */
+/*     $NetBSD: llist.h,v 1.4 2021/12/19 11:36:48 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/null.h>
 
 struct llist_head {
-       struct llist_node       *llh_first;
+       struct llist_node       *first;
 };
 
 struct llist_node {
@@ -47,7 +47,7 @@
 init_llist_head(struct llist_head *head)
 {
 
-       head->llh_first = NULL;
+       head->first = NULL;
 }
 
 #define        llist_entry(NODE, TYPE, FIELD)  container_of(NODE, TYPE, FIELD)
@@ -57,8 +57,7 @@
 {
        bool empty;
 
-       empty = (head->llh_first == NULL);
-       membar_enter();
+       empty = (atomic_load_acquire(&head->first) == NULL);
 
        return empty;
 }
@@ -69,10 +68,10 @@
        struct llist_node *first;
 
        do {
-               first = head->llh_first;
+               first = head->first;
                node->next = first;
                membar_exit();
-       } while (atomic_cas_ptr(&head->llh_first, first, node) != first);
+       } while (atomic_cas_ptr(&head->first, first, node) != first);
 
        return first == NULL;
 }
@@ -82,7 +81,7 @@
 {
        struct llist_node *first;
 
-       first = atomic_swap_ptr(&head->llh_first, NULL);
+       first = atomic_swap_ptr(&head->first, NULL);
        membar_enter();
 
        return first;
@@ -94,23 +93,36 @@
        struct llist_node *first;
 
        do {
-               first = head->llh_first;
-               membar_datadep_consumer();
-       } while (atomic_cas_ptr(&head->llh_first, first, first->next)
+               first = atomic_load_consume(&head->first);
+               if (first == NULL)
+                       return NULL;
+       } while (atomic_cas_ptr(&head->first, first, first->next)
            != first);
-       membar_enter();
 
        return first;
 }
 
+#define        _llist_next(ENTRY, FIELD)                                             \
+({                                                                           \
+       __typeof__((ENTRY)->FIELD.next) _NODE =                               \
+           atomic_load_consume(&(ENTRY)->FIELD.next);                        \
+       (_NODE == NULL ? NULL :                                               \
+           llist_entry(_NODE, __typeof__(*(ENTRY)), FIELD));                 \
+})
+
+#define        llist_for_each_entry(ENTRY, NODE, FIELD)                              \
+       for ((ENTRY) = ((NODE) == NULL ? NULL :                               \
+                   (membar_datadep_consumer(),                               \
+                       llist_entry(NODE, typeof(*(ENTRY)), FIELD)));         \
+               (ENTRY) != NULL;                                              \
+               (ENTRY) = _llist_next(ENTRY, FIELD))
+
 #define        llist_for_each_entry_safe(ENTRY, TMP, NODE, FIELD)                    \
        for ((ENTRY) = ((NODE) == NULL ? NULL :                               \
-                       llist_entry(NODE, typeof(*(ENTRY)), FIELD));          \
-               (ENTRY) == NULL ? 0 :                                         \
                    (membar_datadep_consumer(),                               \
-                       (TMP) = list_entry((ENTRY)->FIELD.next,       \
-                           typeof(*(ENTRY)), FIELD),                         \
-                       1);                                                   \
-                (ENTRY) = (TMP))
+                       llist_entry(NODE, typeof(*(ENTRY)), FIELD)));         \
+               ((ENTRY) == NULL ? 0 :                                        \
+                   ((TMP) = _llist_next(ENTRY, FIELD), 1));                  \
+               (ENTRY) = (TMP))
 
 #endif /* _LINUX_LLIST_H_ */



Home | Main Index | Thread Index | Old Index