From 1c1f9901c2dea7a883342cd03d3906a1bc482583 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Wed, 11 Jul 2018 20:28:29 +0300 Subject: [PATCH] ck_queue: add CK_SLIST_INSERT_PREVPTR and CK_SLIST_REMOVE_PREVPTR These new macros are very convenient for modifying a SLIST after using CK_SLIST_FOREACH_PREVPTR to find an element to remove or a position to insert. FreeBSD sys/queue.h already has SLIST_REMOVE_PREVPTR. I would like to use the new macros in a change that I am planning for FreeBSD kernel: https://reviews.freebsd.org/D16016 https://reviews.freebsd.org/D15905 --- include/ck_queue.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/ck_queue.h b/include/ck_queue.h index 59f9c60..990ab4b 100644 --- a/include/ck_queue.h +++ b/include/ck_queue.h @@ -180,6 +180,12 @@ struct { \ ck_pr_store_ptr(&(head)->cslh_first, elm); \ } while (0) +#define CK_SLIST_INSERT_PREVPTR(prevp, slistelm, elm, field) do { \ + (elm)->field.csle_next = (slistelm); \ + ck_pr_fence_store(); \ + ck_pr_store_ptr(prevp, elm); \ +} while (0) + #define CK_SLIST_REMOVE_AFTER(elm, field) do { \ ck_pr_store_ptr(&(elm)->field.csle_next, \ (elm)->field.csle_next->field.csle_next); \ @@ -201,6 +207,10 @@ struct { \ (head)->cslh_first->field.csle_next); \ } while (0) +#define CK_SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \ + ck_pr_store_ptr(prevptr, (elm)->field.csle_next); \ +} while (0) + #define CK_SLIST_MOVE(head1, head2, field) do { \ ck_pr_store_ptr(&(head1)->cslh_first, (head2)->cslh_first); \ } while (0)