X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=ms-queue%2Fmy_queue.c;h=498fb42b1188bb344bde560c6bd570f468558dbf;hp=9ffb343dd3174ec970da9685c2e203ad1c38f242;hb=d3c94c5b4370fc71d1c12272af29b3a95178f4bd;hpb=6bfec4a14ed32227ccd38e85e111221d89c10d58 diff --git a/ms-queue/my_queue.c b/ms-queue/my_queue.c index 9ffb343..498fb42 100644 --- a/ms-queue/my_queue.c +++ b/ms-queue/my_queue.c @@ -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) - 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); @@ -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 - 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, - &next, - val); + &next, value); } 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, - &tail, - val); + &tail, value); thrd_yield(); } } @@ -104,7 +100,7 @@ unsigned int dequeue(queue_t *q) 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();