From: Mathieu Desnoyers Date: Wed, 12 Jun 2024 20:24:33 +0000 (-0400) Subject: wfstack: make cds_wfs_empty argument const X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c4a5a2ff58023b16d354fc4b056226c3f959566a;p=userspace-rcu.git wfstack: make cds_wfs_empty argument const cds_wfs_empty doesn't modify its argument. Hence, it can be marked as `const`. Signed-off-by: Mathieu Desnoyers Change-Id: Ie125d66296eefecfeb20a8a297b5eb04b42034a2 --- diff --git a/include/urcu/static/wfstack.h b/include/urcu/static/wfstack.h index c46e97d..97c5192 100644 --- a/include/urcu/static/wfstack.h +++ b/include/urcu/static/wfstack.h @@ -106,9 +106,9 @@ static inline bool ___cds_wfs_end(void *node) * * No memory barrier is issued. No mutual exclusion is required. */ -static inline bool _cds_wfs_empty(cds_wfs_stack_ptr_t u_stack) +static inline bool _cds_wfs_empty(cds_wfs_stack_const_ptr_t u_stack) { - struct __cds_wfs_stack *s = u_stack._s; + const struct __cds_wfs_stack *s = u_stack._s; return ___cds_wfs_end(uatomic_load(&s->head, CMM_RELAXED)); } diff --git a/include/urcu/wfstack.h b/include/urcu/wfstack.h index 38e5b6b..66d4150 100644 --- a/include/urcu/wfstack.h +++ b/include/urcu/wfstack.h @@ -96,6 +96,11 @@ typedef union { struct __cds_wfs_stack *_s; struct cds_wfs_stack *s; } __attribute__((__transparent_union__)) cds_wfs_stack_ptr_t; + +typedef union { + const struct __cds_wfs_stack *_s; + const struct cds_wfs_stack *s; +} __attribute__((__transparent_union__)) cds_wfs_stack_const_ptr_t; #if defined(__clang__) #pragma clang diagnostic pop #endif @@ -167,7 +172,7 @@ extern void __cds_wfs_init(struct __cds_wfs_stack *s); * * No memory barrier is issued. No mutual exclusion is required. */ -extern bool cds_wfs_empty(cds_wfs_stack_ptr_t u_stack); +extern bool cds_wfs_empty(cds_wfs_stack_const_ptr_t u_stack); /* * cds_wfs_push: push a node into the stack. @@ -372,9 +377,25 @@ static inline cds_wfs_stack_ptr_t cds_wfs_stack_cast(struct cds_wfs_stack *s) return ret; } +static inline cds_wfs_stack_const_ptr_t cds_wfs_stack_const_cast(const struct __cds_wfs_stack *s) +{ + cds_wfs_stack_const_ptr_t ret = { + ._s = s, + }; + return ret; +} + +static inline cds_wfs_stack_const_ptr_t cds_wfs_stack_const_cast(const struct cds_wfs_stack *s) +{ + cds_wfs_stack_const_ptr_t ret = { + .s = s, + }; + return ret; +} + template static inline bool cds_wfs_empty(T s) { - return cds_wfs_empty(cds_wfs_stack_cast(s)); + return cds_wfs_empty(cds_wfs_stack_const_cast(s)); } template static inline int cds_wfs_push(T s, struct cds_wfs_node *node) diff --git a/src/wfstack.c b/src/wfstack.c index 8fddaec..6308a94 100644 --- a/src/wfstack.c +++ b/src/wfstack.c @@ -34,7 +34,7 @@ void __cds_wfs_init(struct __cds_wfs_stack *s) ___cds_wfs_init(s); } -bool cds_wfs_empty(cds_wfs_stack_ptr_t u_stack) +bool cds_wfs_empty(cds_wfs_stack_const_ptr_t u_stack) { return _cds_wfs_empty(u_stack); }