rcuja: use rcu ja app flavor for shadow hash table
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 12 Aug 2012 20:26:53 +0000 (16:26 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 14 May 2013 14:20:23 +0000 (16:20 +0200)
Since we use call_rcu to delay reclaim of the rcu ja node too, we need
to use the same RCU flavor as the application that calls the RCU JA API.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rcuja/rcuja-internal.h
rcuja/rcuja-shadow-nodes.c
rculfhash.c
urcu/rculfhash.h

index b892a8747cf89b5250369b5558c6830c9647ff33..a5aae07dceeddf5b871772a98d0c1fa06b2390c8 100644 (file)
@@ -37,6 +37,7 @@ struct rcu_ja_shadow_node {
        struct rcu_ja_node *node;       /* reverse mapping and hash table key */
        pthread_mutex_t lock;           /* mutual exclusion on node */
        struct rcu_head head;           /* for deferred node and shadow node reclaim */
+       const struct rcu_flavor_struct *flavor; /* rcu flavor */
 };
 
 struct rcu_ja {
@@ -61,7 +62,7 @@ __attribute__((visibility("protected")))
 int rcuja_shadow_clear_and_free_node(struct cds_lfht *ht,
                struct rcu_ja_node *node);
 __attribute__((visibility("protected")))
-struct cds_lfht *rcuja_create_ht(void);
+struct cds_lfht *rcuja_create_ht(const struct rcu_flavor_struct *flavor);
 __attribute__((visibility("protected")))
 void rcuja_delete_ht(struct cds_lfht *ht);
 
index b737e26711504d9cba41cd8ef478574c491a5377..cfc3aacebe311d5eccca6bc950957e25a57aa64a 100644 (file)
 #include <stdint.h>
 #include <errno.h>
 #include <limits.h>
-
-/*
- * The hash table used by judy array updates only for the shadow node
- * mapping rely on standard urcu_mb flavor. It does not put any
- * requirement on the RCU flavor used by applications using the judy
- * array.
- */
-#include <urcu.h>
-
 #include <urcu/rcuja.h>
 #include <urcu/compiler.h>
 #include <urcu/arch.h>
@@ -190,9 +181,11 @@ struct rcu_ja_shadow_node *rcuja_shadow_lookup_lock(struct cds_lfht *ht,
        struct cds_lfht_iter iter;
        struct cds_lfht_node *lookup_node;
        struct rcu_ja_shadow_node *shadow_node;
+       const struct rcu_flavor_struct *flavor;
        int ret;
 
-       rcu_read_lock();
+       flavor = cds_lfht_rcu_flavor(ht);
+       flavor->read_lock();
        cds_lfht_lookup(ht, hash_pointer(node, hash_seed),
                        match_pointer, node, &iter);
 
@@ -211,7 +204,7 @@ struct rcu_ja_shadow_node *rcuja_shadow_lookup_lock(struct cds_lfht *ht,
                shadow_node = NULL;
        }
 rcu_unlock:
-       rcu_read_unlock();
+       flavor->read_unlock();
        return shadow_node;
 }
 
@@ -230,6 +223,7 @@ int rcuja_shadow_set(struct cds_lfht *ht,
 {
        struct rcu_ja_shadow_node *shadow_node;
        struct cds_lfht_node *ret_node;
+       const struct rcu_flavor_struct *flavor;
 
        shadow_node = calloc(sizeof(*shadow_node), 1);
        if (!shadow_node)
@@ -238,13 +232,14 @@ int rcuja_shadow_set(struct cds_lfht *ht,
        shadow_node->node = node;
        pthread_mutex_init(&shadow_node->lock, NULL);
 
-       rcu_read_lock();
+       flavor = cds_lfht_rcu_flavor(ht);
+       flavor->read_lock();
        ret_node = cds_lfht_add_unique(ht,
                        hash_pointer(node, hash_seed),
                        match_pointer,
                        node,
                        &shadow_node->ht_node);
-       rcu_read_unlock();
+       flavor->read_unlock();
 
        if (ret_node != &shadow_node->ht_node) {
                free(shadow_node);
@@ -269,9 +264,11 @@ int rcuja_shadow_clear_and_free_node(struct cds_lfht *ht,
        struct cds_lfht_iter iter;
        struct cds_lfht_node *lookup_node;
        struct rcu_ja_shadow_node *shadow_node;
+       const struct rcu_flavor_struct *flavor;
        int ret, lockret;
 
-       rcu_read_lock();
+       flavor = cds_lfht_rcu_flavor(ht);
+       flavor->read_lock();
        cds_lfht_lookup(ht, hash_pointer(node, hash_seed),
                        match_pointer, node, &iter);
        lookup_node = cds_lfht_iter_get_node(&iter);
@@ -291,22 +288,22 @@ int rcuja_shadow_clear_and_free_node(struct cds_lfht *ht,
         */
        ret = cds_lfht_del(ht, lookup_node);
        if (!ret) {
-               call_rcu(&shadow_node->head, free_shadow_node_and_node);
+               flavor->update_call_rcu(&shadow_node->head, free_shadow_node_and_node);
        }
        lockret = pthread_mutex_unlock(&shadow_node->lock);
        assert(!lockret);
 rcu_unlock:
-       rcu_read_unlock();
+       flavor->read_unlock();
 
        return ret;
 }
 
 __attribute__((visibility("protected")))
-struct cds_lfht *rcuja_create_ht(void)
+struct cds_lfht *rcuja_create_ht(const struct rcu_flavor_struct *flavor)
 {
-       return cds_lfht_new(1, 1, 0,
+       return _cds_lfht_new(1, 1, 0,
                CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING,
-               NULL);
+               NULL, flavor, NULL);
 }
 
 __attribute__((visibility("protected")))
index 423609d6c188dd79f6392763ad7b8082f2180def..7b8e2fe72976bba5b53498506ee902fbfb359a58 100644 (file)
@@ -2007,3 +2007,8 @@ void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
        }
        __cds_lfht_resize_lazy_launch(ht);
 }
+
+const struct rcu_flavor_struct *cds_lfht_rcu_flavor(struct cds_lfht *ht)
+{
+       return ht->flavor;
+}
index 4d50f08ee892803fa4762ba266846ee067fc9d01..9c382120111c34d31d86fd80e9206d575626534a 100644 (file)
@@ -484,6 +484,11 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size);
                        pos = caa_container_of(cds_lfht_iter_get_node(iter), \
                                        __typeof__(*(pos)), member))
 
+/*
+ * cds_lfht_rcu_flavor: get RCU flavor argument from hash table creation.
+ */
+const struct rcu_flavor_struct *cds_lfht_rcu_flavor(struct cds_lfht *ht);
+
 #ifdef __cplusplus
 }
 #endif
This page took 0.028505 seconds and 4 git commands to generate.