diff --git a/sys/sys/queue.h b/sys/sys/queue.h --- a/sys/sys/queue.h +++ b/sys/sys/queue.h @@ -355,11 +355,6 @@ "first field address", (head), (head)->stqh_last); \ } while (0) -#define STAILQ_ASSERT_EMPTY(head) do { \ - if (!STAILQ_EMPTY((head))) \ - panic("stailq %p is not empty", (head)); \ -} while (0) - /* * QMD_STAILQ_CHECK_TAIL(STAILQ_HEAD *head) * @@ -370,11 +365,23 @@ panic("Stailq %p last element's next pointer is %p, " \ "not NULL", (head), *(head)->stqh_last); \ } while (0) + +#define STAILQ_ASSERT_EMPTY(head) do { \ + if (!STAILQ_EMPTY((head))) \ + panic("stailq %p is not empty", (head)); \ +} while (0); + +#define STAILQ_ASSERT_NONEMPTY(head) do { \ + if (STAILQ_EMPTY((head))) \ + panic("stailq %p is empty", (head)); \ +} while (0); + #else #define QMD_STAILQ_CHECK_EMPTY(head) -#define STAILQ_ASSERT_EMPTY(head) #define QMD_STAILQ_CHECK_TAIL(head) -#endif /* (_KERNEL && INVARIANTS) */ +#define STAILQ_ASSERT_EMPTY(head) +#define STAILQ_ASSERT_NONEMPTY(head) +#endif /* _KERNEL && INVARIANTS */ #define STAILQ_CONCAT(head1, head2) do { \ if (!STAILQ_EMPTY((head2))) { \ @@ -472,6 +479,19 @@ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) +#define STAILQ_SPLIT_AFTER(head, elm, rest, field) do { \ + STAILQ_ASSERT_NONEMPTY((head)); \ + if (&STAILQ_NEXT((elm), field) == (head)->stqh_last) \ + /* 'elm' is the last element in 'head'. */ \ + STAILQ_INIT((rest)); \ + else { \ + STAILQ_FIRST((rest)) = STAILQ_NEXT((elm), field); \ + (rest)->stqh_last = (head)->stqh_last; \ + STAILQ_NEXT((elm), field) = NULL; \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + } \ +} while (0) + #define STAILQ_SWAP(head1, head2, type) do { \ QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \