From e1a3b81e201ccfd019dae3778bd6ba0bd1e545e4 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 1 Sep 2011 09:28:30 -0400 Subject: [PATCH] Make lf stack push return if the stack was empty Signed-off-by: Mathieu Desnoyers --- rculfstack.c | 5 +++-- urcu/rculfstack.h | 3 ++- urcu/static/rculfstack.h | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rculfstack.c b/rculfstack.c index aa906af..f58628c 100644 --- a/rculfstack.c +++ b/rculfstack.c @@ -51,9 +51,10 @@ void cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s) _cds_lfs_init_rcu(s); } -void cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node) +int cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, + struct cds_lfs_node_rcu *node) { - _cds_lfs_push_rcu(s, node); + return _cds_lfs_push_rcu(s, node); } struct cds_lfs_node_rcu *cds_lfs_pop_rcu(struct cds_lfs_stack_rcu *s) diff --git a/urcu/rculfstack.h b/urcu/rculfstack.h index f673952..cf00daf 100644 --- a/urcu/rculfstack.h +++ b/urcu/rculfstack.h @@ -68,7 +68,8 @@ struct cds_lfs_stack_rcu { extern void cds_lfs_node_init_rcu(struct cds_lfs_node_rcu *node); extern void cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s); -extern void cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node); +extern int cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, + struct cds_lfs_node_rcu *node); /* * Acts as a RCU reader. diff --git a/urcu/static/rculfstack.h b/urcu/static/rculfstack.h index 9d69fa7..1df121b 100644 --- a/urcu/static/rculfstack.h +++ b/urcu/static/rculfstack.h @@ -64,9 +64,13 @@ void _cds_lfs_init_rcu(struct cds_lfs_stack_rcu *s) * required if we first read the old head value). This design decision * might be revisited after more throrough benchmarking on various * platforms. + * + * Returns 0 if the stack was empty prior to adding the node. + * Returns non-zero otherwise. */ static inline -void _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *node) +int _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, + struct cds_lfs_node_rcu *node) { struct cds_lfs_node_rcu *head = NULL; @@ -82,6 +86,7 @@ void _cds_lfs_push_rcu(struct cds_lfs_stack_rcu *s, struct cds_lfs_node_rcu *nod if (old_head == head) break; } + return (int) !!((unsigned long) head); } /* -- 2.34.1