+static
+int ja_linear_node_clear_nth(const struct cds_ja_type *type,
+ struct cds_ja_inode *node,
+ struct cds_ja_shadow_node *shadow_node,
+ uint8_t n)
+{
+ uint8_t nr_child;
+ uint8_t *values, *nr_child_ptr;
+ struct cds_ja_inode_flag **pointers;
+ unsigned int i;
+
+ assert(type->type_class == RCU_JA_LINEAR || type->type_class == RCU_JA_POOL);
+
+ nr_child_ptr = &node->u.data[0];
+ dbg_printf("linear clear nth: nr_child_ptr %p\n", nr_child_ptr);
+ nr_child = *nr_child_ptr;
+ assert(nr_child <= type->max_linear_child);
+
+ values = &node->u.data[1];
+ pointers = (struct cds_ja_inode_flag **) align_ptr_size(&values[type->max_linear_child]);
+ for (i = 0; i < nr_child; i++) {
+ if (values[i] == n) {
+ if (pointers[i])
+ break;
+ else
+ return -ENOENT;
+ }
+ }
+ if (i >= nr_child)
+ return -ENOENT;
+ if (shadow_node->fallback_removal_count) {
+ shadow_node->fallback_removal_count--;
+ } else {
+ if (shadow_node->nr_child <= type->min_child) {
+ /* We need to try recompacting the node */
+ return -EFBIG;
+ }
+ }
+ assert(pointers[i] != NULL);
+ rcu_assign_pointer(pointers[i], NULL);
+ /*
+ * Value and nr_child are never changed (would cause ABA issue).
+ * Instead, we leave the pointer to NULL and recompact the node
+ * once in a while. It is allowed to set a NULL pointer to a new
+ * value without recompaction though.
+ * Only update the shadow node accounting.
+ */
+ shadow_node->nr_child--;
+ dbg_printf("linear set nth: %u child, shadow: %u child, for node %p shadow %p\n",
+ (unsigned int) CMM_LOAD_SHARED(*nr_child_ptr),
+ (unsigned int) shadow_node->nr_child,
+ node, shadow_node);
+
+ return 0;
+}
+
+static
+int ja_pool_node_clear_nth(const struct cds_ja_type *type,
+ struct cds_ja_inode *node,
+ struct cds_ja_shadow_node *shadow_node,
+ uint8_t n)
+{
+ struct cds_ja_inode *linear;
+
+ assert(type->type_class == RCU_JA_POOL);
+ linear = (struct cds_ja_inode *)
+ &node->u.data[((unsigned long) n >> (CHAR_BIT - type->nr_pool_order)) << type->pool_size_order];
+ return ja_linear_node_clear_nth(type, linear, shadow_node, n);
+}
+
+static
+int ja_pigeon_node_clear_nth(const struct cds_ja_type *type,
+ struct cds_ja_inode *node,
+ struct cds_ja_shadow_node *shadow_node,
+ uint8_t n)
+{
+ struct cds_ja_inode_flag **ptr;
+
+ assert(type->type_class == RCU_JA_PIGEON);
+ ptr = &((struct cds_ja_inode_flag **) node->u.data)[n];
+ if (!*ptr)
+ return -ENOENT;
+ rcu_assign_pointer(*ptr, NULL);
+ shadow_node->nr_child--;
+ return 0;
+}
+
+/*
+ * _ja_node_clear_nth: clear nth item within a node. Return an error
+ * (negative error value) if it is not found (-ENOENT).
+ */
+static
+int _ja_node_clear_nth(const struct cds_ja_type *type,
+ struct cds_ja_inode *node,
+ struct cds_ja_shadow_node *shadow_node,
+ uint8_t n)
+{
+ switch (type->type_class) {
+ case RCU_JA_LINEAR:
+ return ja_linear_node_clear_nth(type, node, shadow_node, n);
+ case RCU_JA_POOL:
+ return ja_pool_node_clear_nth(type, node, shadow_node, n);
+ case RCU_JA_PIGEON:
+ return ja_pigeon_node_clear_nth(type, node, shadow_node, n);
+ case RCU_JA_NULL:
+ return -ENOENT;
+ default:
+ assert(0);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+