+ 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;
+
+ 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);
+ if (!lookup_node) {
+ shadow_node = NULL;
+ goto rcu_unlock;
+ }
+ shadow_node = caa_container_of(lookup_node,
+ struct rcu_ja_shadow_node, ht_node);
+ ret = pthread_mutex_lock(&shadow_node->lock);
+ assert(!ret);
+ if (cds_lfht_is_node_deleted(lookup_node)) {
+ ret = pthread_mutex_unlock(&shadow_node->lock);
+ assert(!ret);
+ shadow_node = NULL;
+ }
+rcu_unlock:
+ flavor->read_unlock();
+ return shadow_node;
+}
+
+__attribute__((visibility("protected")))
+void rcuja_shadow_unlock(struct rcu_ja_shadow_node *shadow_node)
+{
+ int ret;
+
+ ret = pthread_mutex_unlock(&shadow_node->lock);
+ assert(!ret);
+}
+
+__attribute__((visibility("protected")))
+int rcuja_shadow_set(struct cds_lfht *ht,
+ struct rcu_ja_node *node)
+{
+ 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)
+ return -ENOMEM;
+
+ shadow_node->node = node;
+ pthread_mutex_init(&shadow_node->lock, NULL);
+
+ 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);
+ flavor->read_unlock();
+
+ if (ret_node != &shadow_node->ht_node) {
+ free(shadow_node);
+ return -EEXIST;
+ }
+ return 0;
+}
+
+static
+void free_shadow_node_and_node(struct rcu_head *head)
+{
+ struct rcu_ja_shadow_node *shadow_node =
+ caa_container_of(head, struct rcu_ja_shadow_node, head);
+ free(shadow_node->node);
+ free(shadow_node);
+}
+
+__attribute__((visibility("protected")))
+int rcuja_shadow_clear_and_free_node(struct cds_lfht *ht,
+ struct rcu_ja_node *node)
+{
+ 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;
+
+ 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);
+ if (!lookup_node) {
+ ret = -ENOENT;
+ goto rcu_unlock;
+ }
+ shadow_node = caa_container_of(lookup_node,
+ struct rcu_ja_shadow_node, ht_node);
+ lockret = pthread_mutex_lock(&shadow_node->lock);
+ assert(!lockret);
+
+ /*
+ * Holding the mutex across deletion, and by also re-checking if
+ * the node is deleted with mutex held at lookup ensure that we
+ * don't let RCU JA use a node being removed.
+ */
+ ret = cds_lfht_del(ht, lookup_node);
+ if (!ret) {
+ flavor->update_call_rcu(&shadow_node->head, free_shadow_node_and_node);
+ }
+ lockret = pthread_mutex_unlock(&shadow_node->lock);
+ assert(!lockret);
+rcu_unlock:
+ flavor->read_unlock();
+
+ return ret;
+}
+
+__attribute__((visibility("protected")))
+struct cds_lfht *rcuja_create_ht(const struct rcu_flavor_struct *flavor)
+{
+ return _cds_lfht_new(1, 1, 0,