ms-queue: fixups, add simple race detection
authorBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 03:08:32 +0000 (19:08 -0800)
committerBrian Norris <banorris@uci.edu>
Wed, 6 Mar 2013 03:08:32 +0000 (19:08 -0800)
ms-queue/main.c
ms-queue/my_queue.c

index 51e0e79..210c57a 100644 (file)
@@ -63,7 +63,6 @@ int user_main(int argc, char **argv)
        int *param;
 
        parse_args(argc, argv);
-       iterations = (iterations + (procs >> 1)) / procs;
 
        queue = calloc(1, sizeof(*queue));
        assert(queue);
index 498fb42..67ec680 100644 (file)
@@ -1,5 +1,6 @@
 #include <threads.h>
 #include <stdlib.h>
+#include "librace.h"
 
 #include "my_queue.h"
 
@@ -54,7 +55,7 @@ void enqueue(queue_t *q, unsigned int val)
        pointer tmp;
 
        node = new_node();
-       q->nodes[node].value = val;
+       store_32(&q->nodes[node].value, val);
        tmp = atomic_load(&q->nodes[node].next);
        set_ptr(&tmp, 0); // NULL
        atomic_store(&q->nodes[node].next, tmp);
@@ -105,7 +106,7 @@ unsigned int dequeue(queue_t *q)
                                                MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
                                thrd_yield();
                        } else {
-                               value = q->nodes[get_ptr(next)].value;
+                               value = load_32(&q->nodes[get_ptr(next)].value);
                                success = atomic_compare_exchange_weak(&q->head,
                                                &head,
                                                MAKE_POINTER(get_ptr(next), get_count(head) + 1));