From: Mathieu Desnoyers Date: Sun, 9 Jun 2013 17:47:28 +0000 (-0400) Subject: rcuja ranges: update API X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=678624e7fc7e9deb637590630b2a3563f9e1bbf9;p=urcu.git rcuja ranges: update API Signed-off-by: Mathieu Desnoyers --- diff --git a/rcuja/rcuja-range.c b/rcuja/rcuja-range.c index 19eebe1..761affb 100644 --- a/rcuja/rcuja-range.c +++ b/rcuja/rcuja-range.c @@ -92,6 +92,7 @@ * A range type never changes otherwise. */ +#define CDS_JA_RANGE_KEY_BITS 64 struct cds_ja_range *cds_ja_range_lookup(struct cds_ja *ja, uint64_t key) { @@ -367,26 +368,32 @@ unlock_retry: goto retry; } -int cds_ja_range_init(struct cds_ja *ja) +struct cds_ja *_cds_ja_range_new(const struct rcu_flavor_struct *flavor) { - struct cds_ja_node *node; struct cds_ja_range *range; + struct cds_ja *ja; int ret; - /* - * Sanity check: should be empty. - */ - node = cds_ja_lookup_above_equal(ja, 0, NULL); - if (node) - return -EINVAL; + ja = _cds_ja_new(CDS_JA_RANGE_KEY_BITS, flavor); + if (!ja) + return NULL; range = range_create(0, UINT64_MAX, CDS_JA_RANGE_FREE); if (!range) - return -EINVAL; + goto free_ja; ret = cds_ja_add(ja, 0, &range->ja_node); - return ret; + if (ret) + goto free_range; + return ja; + +free_range: + free_range(range); +free_ja: + ret = cds_ja_destroy(ja); + assert(!ret); + return NULL; } -int cds_ja_range_fini(struct cds_ja *ja) +int cds_ja_range_destroy(struct cds_ja *ja) { uint64_t key; struct cds_ja_node *ja_node; @@ -401,13 +408,14 @@ int cds_ja_range_fini(struct cds_ja *ja) range = caa_container_of(ja_node, struct cds_ja_range, ja_node); ret = cds_ja_del(ja, key, &range->ja_node); - if (ret) { - goto end; - } + if (ret) + goto error; /* Alone using Judy array, OK to free now */ free_range(range); } } -end: + return cds_ja_destroy(ja); + +error: return ret; } diff --git a/urcu/rcuja-range.h b/urcu/rcuja-range.h index 31bce15..e1a54a2 100644 --- a/urcu/rcuja-range.h +++ b/urcu/rcuja-range.h @@ -51,9 +51,6 @@ struct cds_ja_range { struct rcu_head head; }; -int cds_ja_range_init(struct cds_ja *ja); -int cds_ja_range_fini(struct cds_ja *ja); - struct cds_ja_range *cds_ja_range_lookup(struct cds_ja *ja, uint64_t key); struct cds_ja_range *cds_ja_range_lock(struct cds_ja_range *range); @@ -66,6 +63,16 @@ struct cds_ja_range *cds_ja_range_add(struct cds_ja *ja, int cds_ja_range_del(struct cds_ja *ja, struct cds_ja_range *range); +struct cds_ja *_cds_ja_range_new(const struct rcu_flavor_struct *flavor); + +static inline +struct cds_ja *cds_ja_range_new(void) +{ + return _cds_ja_range_new(&rcu_flavor); +} + +int cds_ja_range_destroy(struct cds_ja *ja); + #ifdef __cplusplus } #endif