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 c2a910408a17d97433d574239625a686e1f4af70..cd48d78267f88ebb149fcfdfabce3fc12df383cf 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 8813e37bb44ec93671b505ff00fca1e192018ba6..51e0e79c478e64c0267ba794b074115b7f69d822 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 9ffb343dd3174ec970da9685c2e203ad1c38f242..33a62925c7a6a195fc0002cd54b2d3ce8807553a 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();