rcuja ranges: update API
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 9 Jun 2013 17:47:28 +0000 (13:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 9 Jun 2013 17:47:28 +0000 (13:47 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rcuja/rcuja-range.c
urcu/rcuja-range.h

index 19eebe1d844bc5c69d4de23c99b8456bab1dde76..761affb249e343a39e9911621a82456e0f35b4dc 100644 (file)
@@ -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;
 }
index 31bce15a727a77e24e9f1906995629e60f7b6dea..e1a54a279accff3887eec0a8e6ed97d3bf3d36b1 100644 (file)
@@ -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
This page took 0.027492 seconds and 4 git commands to generate.