wfstack: make cds_wfs_empty argument const
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 12 Jun 2024 20:24:33 +0000 (16:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 12 Jun 2024 20:25:23 +0000 (16:25 -0400)
cds_wfs_empty doesn't modify its argument. Hence, it can be
marked as `const`.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie125d66296eefecfeb20a8a297b5eb04b42034a2

include/urcu/static/wfstack.h
include/urcu/wfstack.h
src/wfstack.c

index c46e97d9f25197e0e701a55ef24b0975bd1b2aac..97c5192a8f975c51cd000b296e2953526c3af865 100644 (file)
@@ -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));
 }
index 38e5b6b2dcb3099dec87f8a6b3fb4f5750e93fb1..66d415027ab33577b19cee609889558cada6b9fa 100644 (file)
@@ -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<typename T> 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<typename T> static inline int cds_wfs_push(T s, struct cds_wfs_node *node)
index 8fddaecf32a9c1d2e1f3326947f0f7e5c71ed2ef..6308a94b9876fa0ac0c99ed41a288471dbfa7fc9 100644 (file)
@@ -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);
 }
This page took 0.027783 seconds and 4 git commands to generate.