Print this page




  21 /*
  22  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 
  25 /*
  26  * Generic doubly-linked list implementation
  27  */
  28 
  29 #include <sys/list.h>
  30 #include <sys/list_impl.h>
  31 #include <sys/types.h>
  32 #include <sys/sysmacros.h>
  33 #ifdef _KERNEL
  34 #include <sys/debug.h>
  35 #else
  36 #include <assert.h>
  37 #define ASSERT(a)       assert(a)
  38 #endif
  39 
  40 #ifdef lint
  41 extern list_node_t *list_d2l(list_t *list, void *obj);










  42 #else
  43 #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
  44 #endif
  45 #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
  46 #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
  47 
  48 #define list_insert_after_node(list, node, object) {    \
  49         list_node_t *lnew = list_d2l(list, object);     \
  50         lnew->list_prev = (node);                    \
  51         lnew->list_next = (node)->list_next;              \
  52         (node)->list_next->list_prev = lnew;              \
  53         (node)->list_next = lnew;                    \
  54 }
  55 
  56 #define list_insert_before_node(list, node, object) {   \
  57         list_node_t *lnew = list_d2l(list, object);     \
  58         lnew->list_next = (node);                    \
  59         lnew->list_prev = (node)->list_prev;              \
  60         (node)->list_prev->list_next = lnew;              \
  61         (node)->list_prev = lnew;                    \




  21 /*
  22  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 
  25 /*
  26  * Generic doubly-linked list implementation
  27  */
  28 
  29 #include <sys/list.h>
  30 #include <sys/list_impl.h>
  31 #include <sys/types.h>
  32 #include <sys/sysmacros.h>
  33 #ifdef _KERNEL
  34 #include <sys/debug.h>
  35 #else
  36 #include <assert.h>
  37 #define ASSERT(a)       assert(a)
  38 #endif
  39 
  40 #ifdef lint
  41 static list_node_t *
  42 list_d2l(list_t *list, void *obj)
  43 {
  44         /* Pretty version for lint... */
  45         uint64_t *offset = (uint64_t *)obj;
  46 
  47         if (!IS_P2ALIGNED(obj, 8))
  48                 return (NULL);
  49 
  50         return ((list_node_t *)(offset + (list->list_offset >> 3)));
  51 }
  52 #else
  53 #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
  54 #endif
  55 #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
  56 #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
  57 
  58 #define list_insert_after_node(list, node, object) {    \
  59         list_node_t *lnew = list_d2l(list, object);     \
  60         lnew->list_prev = (node);                    \
  61         lnew->list_next = (node)->list_next;              \
  62         (node)->list_next->list_prev = lnew;              \
  63         (node)->list_next = lnew;                    \
  64 }
  65 
  66 #define list_insert_before_node(list, node, object) {   \
  67         list_node_t *lnew = list_d2l(list, object);     \
  68         lnew->list_next = (node);                    \
  69         lnew->list_prev = (node)->list_prev;              \
  70         (node)->list_prev->list_next = lnew;              \
  71         (node)->list_prev = lnew;                    \