ms-queue: bugfix - get_ptr() and get_count() were switched
authorBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 02:17:49 +0000 (18:17 -0800)
committerBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 02:20:34 +0000 (18:20 -0800)
I ported the implementation wrong, so that we were extracting bits from
the wrong field.

ms-queue/my_queue.c
ms-queue/my_queue.h

index 33a62925c7a6a195fc0002cd54b2d3ce8807553a..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)
 
-       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);
index 5877a680b7c634b636af7d0b1d994b0004ce3387..c92e420657c1847ec3575156be8e6a7b133e2dae 100644 (file)
@@ -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;