ms-queue: cleanups
authorBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 02:17:25 +0000 (18:17 -0800)
committerBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 02:20:34 +0000 (18:20 -0800)
ms-queue/Makefile
ms-queue/main.c
ms-queue/my_queue.c

index c2a9104..cd48d78 100644 (file)
@@ -8,7 +8,7 @@ OBJECTS = main.o my_queue.o
 all: $(TESTNAME)
 
 $(TESTNAME): $(HEADERS) $(OBJECTS)
-       $(CC) -o $@ $^ $(CPPFLAGS) $(LDFLAGS)
+       $(CC) -o $@ $(OBJECTS) $(CPPFLAGS) $(LDFLAGS)
 
 %.o: %.c
        $(CC) -c -o $@ $< $(CPPFLAGS)
index 8813e37..51e0e79 100644 (file)
@@ -43,15 +43,17 @@ static void parse_args(int argc, char **argv)
 
 static void main_task(void *param)
 {
-       unsigned i, j;
-       unsigned val;
+       unsigned int i, j;
+       unsigned int val;
        int pid = *((int *)param);
 
        for (i = 0; i < iterations; i++) {
                val = 1 + pid * iterations + i;
+               printf("worker %d, enqueueing: %u\n", pid, val);
                enqueue(queue, val);
 
                val = dequeue(queue);
+               printf("worker %d, dequeued: %u\n", pid, val);
        }
 }
 
index 9ffb343..33a6292 100644 (file)
@@ -66,18 +66,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 +102,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();