[lttng-dev] [urcu][RFC][PATCH] lfstack, wfcqueue: do not pass NULL as value to atomic_xchg
Emilio G. Cota
cota at braap.org
Mon Oct 13 22:31:25 EDT 2014
atomic_xchg expects a pointer and a value. The value is sign
extended to unsigned long, and the sign is obtained from
#define caa_is_signed_type(type) ((type) -1 < (type) 0)
If -Wextra is enabled, gcc then throws an "ordered comparison
of pointer and null pointer" warning when the value passed to
atomic_xchg is NULL.
The appended is just a quick fix that doesn't fix the real issue.
For this I tried a few things, and the simplest change is to
just do an unconditional cast to unsigned long. This seems to work
for me but I must be missing something--FWIW here's a test program:
https://gist.github.com/cota/9ff275d4dddde302cade
Note that Mathieu worked on this in the past. See commit
4b5f005 gcc warning fixes: -Wsign-compare and -Wextra
Signed-off-by: Emilio G. Cota <cota at braap.org>
---
urcu/static/lfstack.h | 2 +-
urcu/static/wfcqueue.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/urcu/static/lfstack.h b/urcu/static/lfstack.h
index 63af91a..32076ab 100644
--- a/urcu/static/lfstack.h
+++ b/urcu/static/lfstack.h
@@ -237,7 +237,7 @@ struct cds_lfs_head *___cds_lfs_pop_all(cds_lfs_stack_ptr_t u_s)
* taking care to order writes to each node prior to the full
* memory barrier after this uatomic_xchg().
*/
- return uatomic_xchg(&s->head, NULL);
+ return uatomic_xchg(&s->head, 0);
}
/*
diff --git a/urcu/static/wfcqueue.h b/urcu/static/wfcqueue.h
index 48b2625..deddc5f 100644
--- a/urcu/static/wfcqueue.h
+++ b/urcu/static/wfcqueue.h
@@ -518,7 +518,7 @@ ___cds_wfcq_splice(
* uatomic_xchg, as well as tail pointer vs head node
* address.
*/
- head = uatomic_xchg(&src_q_head->node.next, NULL);
+ head = uatomic_xchg(&src_q_head->node.next, 0);
if (head)
break; /* non-empty */
if (CMM_LOAD_SHARED(src_q_tail->p) == &src_q_head->node)
--
1.8.3
More information about the lttng-dev
mailing list