ms-queue: bugfix - get_ptr() and get_count() were switched
[model-checker-benchmarks.git] / ms-queue / my_queue.c
index 9ffb343dd3174ec970da9685c2e203ad1c38f242..498fb42b1188bb344bde560c6bd570f468558dbf 100644 (file)
@@ -31,8 +31,6 @@ void init_queue(queue_t *q, int num_threads)
        tail = MAKE_POINTER(1, 0);
        next = MAKE_POINTER(0, 0); // (NULL, 0)
 
        tail = MAKE_POINTER(1, 0);
        next = MAKE_POINTER(0, 0); // (NULL, 0)
 
-       atomic_init(&q->nodes[0].next, 0); // assumed inititalized in original example
-
        atomic_store(&q->head, head);
        atomic_store(&q->tail, tail);
        atomic_store(&q->nodes[1].next, next);
        atomic_store(&q->head, head);
        atomic_store(&q->tail, tail);
        atomic_store(&q->nodes[1].next, next);
@@ -66,18 +64,16 @@ void enqueue(queue_t *q, unsigned int val)
                next = atomic_load(&q->nodes[get_ptr(tail)].next);
                if (tail == atomic_load(&q->tail)) {
                        if (get_ptr(next) == 0) { // == NULL
                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);
+                               pointer value = MAKE_POINTER(node, get_count(next) + 1);
                                success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
                                success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
-                                               &next,
-                                               val);
+                                               &next, value);
                        }
                        if (!success) {
                                unsigned int ptr = get_ptr(atomic_load(&q->nodes[get_ptr(tail)].next));
                        }
                        if (!success) {
                                unsigned int ptr = get_ptr(atomic_load(&q->nodes[get_ptr(tail)].next));
-                               pointer val = MAKE_POINTER(ptr,
+                               pointer value = MAKE_POINTER(ptr,
                                                get_count(tail) + 1);
                                atomic_compare_exchange_strong(&q->tail,
                                                get_count(tail) + 1);
                                atomic_compare_exchange_strong(&q->tail,
-                                               &tail,
-                                               val);
+                                               &tail, value);
                                thrd_yield();
                        }
                }
                                thrd_yield();
                        }
                }
@@ -104,7 +100,7 @@ unsigned int dequeue(queue_t *q)
                                if (get_ptr(next) == 0) { // NULL
                                        return 0; // NULL
                                }
                                if (get_ptr(next) == 0) { // NULL
                                        return 0; // NULL
                                }
-                               atomic_compare_exchange_weak(&q->tail,
+                               atomic_compare_exchange_strong(&q->tail,
                                                &tail,
                                                MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
                                thrd_yield();
                                                &tail,
                                                MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
                                thrd_yield();