pointer next;
pointer tmp;
+ /* Get a fresh node, set its value field, then set it's next reference to null */
node = new_node();
store_32(&q->nodes[node].value, val);
tmp = atomic_load_explicit(&q->nodes[node].next, relaxed);
atomic_store_explicit(&q->nodes[node].next, tmp, relaxed);
while (!success) {
- tail = atomic_load_explicit(&q->tail, acquire);
- next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire);
+ //tail isn't actually synchronization point
+ tail = atomic_load_explicit(&q->tail, relaxed);
+ //acquire reference
+ next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, relaxed);
if (tail == atomic_load_explicit(&q->tail, relaxed)) {
if (get_ptr(next) == 0) { // == NULL
pointer value = MAKE_POINTER(node, get_count(next) + 1);
success = atomic_compare_exchange_strong_explicit(&q->nodes[get_ptr(tail)].next,
- &next, value, memory_order_acq_rel, memory_order_acq_rel);
+ &next, value, memory_order_release, memory_order_release);
}
if (!success) {
- unsigned int ptr = get_ptr(atomic_load_explicit(&q->nodes[get_ptr(tail)].next, memory_order_seq_cst));
+ unsigned int ptr = get_ptr(atomic_load_explicit(&q->nodes[get_ptr(tail)].next, memory_order_relaxed));
pointer value = MAKE_POINTER(ptr,
get_count(tail) + 1);
atomic_compare_exchange_strong_explicit(&q->tail,
&tail, value,
- memory_order_acq_rel, memory_order_acq_rel);
- thrd_yield();
+ memory_order_relaxed, memory_order_relaxed);
}
}
}
atomic_compare_exchange_strong_explicit(&q->tail,
&tail,
MAKE_POINTER(node, get_count(tail) + 1),
- memory_order_acq_rel, memory_order_acq_rel);
+ memory_order_relaxed, memory_order_relaxed);
}
unsigned int dequeue(queue_t *q)
pointer next;
while (!success) {
- head = atomic_load_explicit(&q->head, acquire);
- tail = atomic_load_explicit(&q->tail, acquire);
+ head = atomic_load_explicit(&q->head, relaxed);
+ tail = atomic_load_explicit(&q->tail, relaxed);
next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire);
if (atomic_load_explicit(&q->head, relaxed) == head) {
if (get_ptr(head) == get_ptr(tail)) {
atomic_compare_exchange_strong_explicit(&q->tail,
&tail,
MAKE_POINTER(get_ptr(next), get_count(tail) + 1),
- memory_order_acq_rel, memory_order_acq_rel);
- thrd_yield();
+ memory_order_relaxed, memory_order_relaxed);
} else {
value = load_32(&q->nodes[get_ptr(next)].value);
success = atomic_compare_exchange_strong_explicit(&q->head,
&head,
MAKE_POINTER(get_ptr(next), get_count(head) + 1),
- memory_order_acq_rel, memory_order_acq_rel);
- if (!success)
- thrd_yield();
+ memory_order_relaxed, memory_order_relaxed);
}
}
}