- smp->nodes[node].value = val;
- smp->nodes[node].next.sep.ptr = NULL;
-
- for (success = FALSE; success == FALSE; ) {
- tail.con = smp->tail.con;
- next.con = smp->nodes[tail.sep.ptr].next.con;
- if (tail.con == smp->tail.con) {
- if (next.sep.ptr == NULL) {
- success = cas(&smp->nodes[tail.sep.ptr].next,
- next.con,
- MAKE_LONG(node, next.sep.count+1));
+ q->nodes[node].value = val;
+ tmp = atomic_load(&q->nodes[node].next);
+ set_ptr(&tmp, 0); // NULL
+ atomic_store(&q->nodes[node].next, tmp);
+
+ while (!success) {
+ tail = atomic_load(&q->tail);
+ next = atomic_load(&q->nodes[get_ptr(tail)].next);
+ if (tail == atomic_load(&q->tail)) {
+ if (get_ptr(next) == 0) { // == NULL
+ pointer val = MAKE_POINTER(node, get_count(next) + 1);
+ success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
+ &next,
+ val);