From d3c94c5b4370fc71d1c12272af29b3a95178f4bd Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 5 Mar 2013 18:17:49 -0800 Subject: [PATCH 1/1] ms-queue: bugfix - get_ptr() and get_count() were switched I ported the implementation wrong, so that we were extracting bits from the wrong field. --- ms-queue/my_queue.c | 2 -- ms-queue/my_queue.h | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ms-queue/my_queue.c b/ms-queue/my_queue.c index 33a6292..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); diff --git a/ms-queue/my_queue.h b/ms-queue/my_queue.h index 5877a68..c92e420 100644 --- a/ms-queue/my_queue.h +++ b/ms-queue/my_queue.h @@ -11,8 +11,8 @@ typedef atomic_ullong pointer_t; static inline void set_count(pointer *p, unsigned int val) { *p = (*p & ~COUNT_MASK) | ((pointer)val << 32); } static inline void set_ptr(pointer *p, unsigned int val) { *p = (*p & ~PTR_MASK) | val; } -static inline unsigned int get_count(pointer p) { return p & PTR_MASK; } -static inline unsigned int get_ptr(pointer p) { return (p & COUNT_MASK) >> 32; } +static inline unsigned int get_count(pointer p) { return (p & COUNT_MASK) >> 32; } +static inline unsigned int get_ptr(pointer p) { return p & PTR_MASK; } typedef struct node { unsigned int value; -- 2.34.1