From: Mathieu Desnoyers Date: Sun, 9 Jun 2013 21:15:11 +0000 (-0400) Subject: rcuja range: range add return error value X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=cd7eb7a38f2a34ff10674795f3022f676b201e49;p=urcu.git rcuja range: range add return error value Signed-off-by: Mathieu Desnoyers --- diff --git a/rcuja/rcuja-range.c b/rcuja/rcuja-range.c index faf60ce..00d68be 100644 --- a/rcuja/rcuja-range.c +++ b/rcuja/rcuja-range.c @@ -209,7 +209,7 @@ void rcu_free_range(struct cds_ja *ja, struct cds_ja_range *range) free_range_cb); } -struct cds_ja_range *cds_ja_range_add(struct cds_ja *ja, +int cds_ja_range_add(struct cds_ja *ja, uint64_t start, /* inclusive */ uint64_t end, /* inclusive */ void *priv) @@ -230,7 +230,7 @@ retry: old_range = caa_container_of(old_node, struct cds_ja_range, ja_node); switch (CMM_LOAD_SHARED(old_range->type)) { case CDS_JA_RANGE_ALLOCATED: - return NULL; + return -EEXIST; case CDS_JA_RANGE_FREE: break; case CDS_JA_RANGE_REMOVED: @@ -245,7 +245,7 @@ retry: switch (CMM_LOAD_SHARED(old_range->type)) { case CDS_JA_RANGE_ALLOCATED: case CDS_JA_RANGE_FREE: /* fall-through */ - return NULL; + return -EEXIST; case CDS_JA_RANGE_REMOVED: goto retry; } @@ -315,7 +315,7 @@ retry: rcu_free_range(ja, old_range); - return new_range; + return 0; } int cds_ja_range_del(struct cds_ja *ja, struct cds_ja_range *range) diff --git a/tests/test_urcu_ja_range.c b/tests/test_urcu_ja_range.c index b36e346..ddd52dc 100644 --- a/tests/test_urcu_ja_range.c +++ b/tests/test_urcu_ja_range.c @@ -296,9 +296,13 @@ void *test_ja_rw_thr_writer(void *_count) end = tmp; } rcu_read_lock(); - range = cds_ja_range_add(test_ja, start, end, NULL); - if (!range) { - fprintf(stderr, "Error in cds_ja_range_add\n"); + ret = cds_ja_range_add(test_ja, start, end, NULL); + if (ret) { + if (ret == -EEXIST) { + URCU_TLS(nr_addexist)++; + } else { + assert(0); + } } else { URCU_TLS(nr_add)++; } @@ -371,13 +375,13 @@ int do_mt_populate_ja(void) key = (unsigned long) iter; key *= key_mul; rcu_read_lock(); - range = cds_ja_range_add(test_ja, key, key, NULL); + ret = cds_ja_range_add(test_ja, key, key, NULL); URCU_TLS(nr_add)++; URCU_TLS(nr_writes)++; rcu_read_unlock(); - if (!range) { - fprintf(stderr, "Error adding range %" PRIu64 "\n", - key); + if (ret) { + fprintf(stderr, "Error (%d) adding range %" PRIu64 "\n", + ret, key); assert(0); } } diff --git a/urcu/rcuja-range.h b/urcu/rcuja-range.h index a1ef3af..feedc5b 100644 --- a/urcu/rcuja-range.h +++ b/urcu/rcuja-range.h @@ -38,7 +38,7 @@ struct cds_ja_range *cds_ja_range_lock(struct cds_ja_range *range); void cds_ja_range_unlock(struct cds_ja_range *range); -struct cds_ja_range *cds_ja_range_add(struct cds_ja *ja, +int cds_ja_range_add(struct cds_ja *ja, uint64_t start, /* inclusive */ uint64_t end, /* inclusive */ void *priv);