rcuja: various fixes
[userspace-rcu.git] / rcuja / rcuja-shadow-nodes.c
index e042cf20abf460557166a457eb6d77bef225e4e2..3a5de33669a9f53db204e6e473c9e928f48803c7 100644 (file)
@@ -176,7 +176,7 @@ int match_pointer(struct cds_lfht_node *node, const void *key)
 
 __attribute__((visibility("protected")))
 struct cds_ja_shadow_node *rcuja_shadow_lookup_lock(struct cds_lfht *ht,
-               struct cds_ja_node *node)
+               struct cds_ja_inode *node)
 {
        struct cds_lfht_iter iter;
        struct cds_lfht_node *lookup_node;
@@ -196,6 +196,7 @@ struct cds_ja_shadow_node *rcuja_shadow_lookup_lock(struct cds_lfht *ht,
        }
        shadow_node = caa_container_of(lookup_node,
                        struct cds_ja_shadow_node, ht_node);
+       dbg_printf("Lock %p\n", shadow_node->lock);
        ret = pthread_mutex_lock(shadow_node->lock);
        assert(!ret);
        if (cds_lfht_is_node_deleted(lookup_node)) {
@@ -213,13 +214,14 @@ void rcuja_shadow_unlock(struct cds_ja_shadow_node *shadow_node)
 {
        int ret;
 
+       dbg_printf("Unlock %p\n", shadow_node->lock);
        ret = pthread_mutex_unlock(shadow_node->lock);
        assert(!ret);
 }
 
 __attribute__((visibility("protected")))
 int rcuja_shadow_set(struct cds_lfht *ht,
-               struct cds_ja_node *new_node,
+               struct cds_ja_inode *new_node,
                struct cds_ja_shadow_node *inherit_from)
 {
        struct cds_ja_shadow_node *shadow_node;
@@ -261,6 +263,14 @@ int rcuja_shadow_set(struct cds_lfht *ht,
        return 0;
 }
 
+static
+void free_shadow_node(struct rcu_head *head)
+{
+       struct cds_ja_shadow_node *shadow_node =
+               caa_container_of(head, struct cds_ja_shadow_node, head);
+       free(shadow_node);
+}
+
 static
 void free_shadow_node_and_node(struct rcu_head *head)
 {
@@ -270,6 +280,15 @@ void free_shadow_node_and_node(struct rcu_head *head)
        free(shadow_node);
 }
 
+static
+void free_shadow_node_and_lock(struct rcu_head *head)
+{
+       struct cds_ja_shadow_node *shadow_node =
+               caa_container_of(head, struct cds_ja_shadow_node, head);
+       free(shadow_node->lock);
+       free(shadow_node);
+}
+
 static
 void free_shadow_node_and_node_and_lock(struct rcu_head *head)
 {
@@ -282,17 +301,19 @@ void free_shadow_node_and_node_and_lock(struct rcu_head *head)
 
 __attribute__((visibility("protected")))
 int rcuja_shadow_clear(struct cds_lfht *ht,
-               struct cds_ja_node *node,
+               struct cds_ja_inode *node,
+               struct cds_ja_shadow_node *shadow_node,
                unsigned int flags)
 {
        struct cds_lfht_iter iter;
        struct cds_lfht_node *lookup_node;
-       struct cds_ja_shadow_node *shadow_node;
        const struct rcu_flavor_struct *flavor;
        int ret, lockret;
+       int lookup_shadow = 0;
 
        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);
@@ -300,10 +321,14 @@ int rcuja_shadow_clear(struct cds_lfht *ht,
                ret = -ENOENT;
                goto rcu_unlock;
        }
-       shadow_node = caa_container_of(lookup_node,
-                       struct cds_ja_shadow_node, ht_node);
-       lockret = pthread_mutex_lock(shadow_node->lock);
-       assert(!lockret);
+
+       if (!shadow_node) {
+               shadow_node = caa_container_of(lookup_node,
+                               struct cds_ja_shadow_node, ht_node);
+               lockret = pthread_mutex_lock(shadow_node->lock);
+               assert(!lockret);
+               lookup_shadow = 1;
+       }
 
        /*
         * Holding the mutex across deletion, and by also re-checking if
@@ -312,17 +337,28 @@ int rcuja_shadow_clear(struct cds_lfht *ht,
         */
        ret = cds_lfht_del(ht, lookup_node);
        if (!ret) {
-               assert(flags & RCUJA_SHADOW_CLEAR_FREE_NODE);
-               if (flags & RCUJA_SHADOW_CLEAR_FREE_LOCK) {
-                       flavor->update_call_rcu(&shadow_node->head,
-                               free_shadow_node_and_node_and_lock);
+               if (flags & RCUJA_SHADOW_CLEAR_FREE_NODE) {
+                       if (flags & RCUJA_SHADOW_CLEAR_FREE_LOCK) {
+                               flavor->update_call_rcu(&shadow_node->head,
+                                       free_shadow_node_and_node_and_lock);
+                       } else {
+                               flavor->update_call_rcu(&shadow_node->head,
+                                       free_shadow_node_and_node);
+                       }
                } else {
-                       flavor->update_call_rcu(&shadow_node->head,
-                               free_shadow_node_and_node);
+                       if (flags & RCUJA_SHADOW_CLEAR_FREE_LOCK) {
+                               flavor->update_call_rcu(&shadow_node->head,
+                                       free_shadow_node_and_lock);
+                       } else {
+                               flavor->update_call_rcu(&shadow_node->head,
+                                       free_shadow_node);
+                       }
                }
        }
-       lockret = pthread_mutex_unlock(shadow_node->lock);
-       assert(!lockret);
+       if (lookup_shadow) {
+               lockret = pthread_mutex_unlock(shadow_node->lock);
+               assert(!lockret);
+       }
 rcu_unlock:
        flavor->read_unlock();
 
This page took 0.02516 seconds and 4 git commands to generate.