ms-queue: relax the second load of head/tail
authorBrian Norris <banorris@uci.edu>
Fri, 8 Mar 2013 02:09:18 +0000 (18:09 -0800)
committerBrian Norris <banorris@uci.edu>
Fri, 8 Mar 2013 02:09:18 +0000 (18:09 -0800)
ms-queue/my_queue.c

index efab2377d310efdf63723f6b2e188af4023c86e8..d65840797b34e88402d78fe1b4b944533a2873dc 100644 (file)
@@ -70,7 +70,7 @@ void enqueue(queue_t *q, unsigned int val)
        while (!success) {
                tail = atomic_load_explicit(&q->tail, acquire);
                next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire);
-               if (tail == atomic_load_explicit(&q->tail, acquire)) {
+               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,
@@ -105,7 +105,7 @@ unsigned int dequeue(queue_t *q)
                head = atomic_load_explicit(&q->head, acquire);
                tail = atomic_load_explicit(&q->tail, acquire);
                next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire);
-               if (atomic_load_explicit(&q->head, acquire) == head) {
+               if (atomic_load_explicit(&q->head, relaxed) == head) {
                        if (get_ptr(head) == get_ptr(tail)) {
                                if (get_ptr(next) == 0) { // NULL
                                        return 0; // NULL