ms-queue: don't initialize node 0
[model-checker-benchmarks.git] / ms-queue / my_queue.c
index efab2377d310efdf63723f6b2e188af4023c86e8..8a74060fb458e935b67faafc9322fdc4c3d445e2 100644 (file)
@@ -31,9 +31,6 @@ void init_queue(queue_t *q, int num_threads)
        for (i = 0; i < num_threads; i++)
                node_nums[i] = 2 + i;
 
-       /* Note: needed to add this init manually */
-       atomic_init(&q->nodes[0].next, 0);
-
        /* initialize queue */
        head = MAKE_POINTER(1, 0);
        tail = MAKE_POINTER(1, 0);
@@ -70,7 +67,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 +102,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