save fixed ms-queue
authorPeizhao Ou <peizhaoo@uci.edu>
Wed, 3 Sep 2014 21:09:29 +0000 (14:09 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Wed, 3 Sep 2014 21:09:29 +0000 (14:09 -0700)
ms-queue/main.c
ms-queue/my_queue.c
ms-queue/my_queue.h

index b541b01..e464138 100644 (file)
@@ -23,19 +23,21 @@ int get_thread_num()
        return -1;
 }
 
+bool succ1, succ2;
+
 static void main_task(void *param)
 {
        unsigned int val;
        int pid = *((int *)param);
-
        if (!pid) {
                input[0] = 17;
                enqueue(queue, input[0]);
-               output[0] = dequeue(queue);
+               succ1 = dequeue(queue, &output[0]);
+               //printf("Dequeue: %d\n", output[0]);
        } else {
                input[1] = 37;
                enqueue(queue, input[1]);
-               output[1] = dequeue(queue);
+               succ2 = dequeue(queue, &output[1]);
        }
 }
 
@@ -70,7 +72,10 @@ int user_main(int argc, char **argv)
                printf("input[%d] = %u\n", i, input[i]);
        for (i = 0; i < num_threads; i++)
                printf("output[%d] = %u\n", i, output[i]);
-       MODEL_ASSERT(in_sum == out_sum);
+       if (succ1 && succ2)
+               MODEL_ASSERT(in_sum == out_sum);
+       else
+               MODEL_ASSERT (false);
 
        free(param);
        free(threads);
index ef35552..6c0ccd4 100644 (file)
@@ -120,9 +120,8 @@ void enqueue(queue_t *q, unsigned int val)
                        release, release);
 }
 
-unsigned int dequeue(queue_t *q)
+bool dequeue(queue_t *q, unsigned int *retVal)
 {
-       unsigned int value;
        int success = 0;
        pointer head;
        pointer tail;
@@ -139,7 +138,7 @@ unsigned int dequeue(queue_t *q)
                                MODEL_ASSERT(get_ptr(next) != POISON_IDX);
 
                                if (get_ptr(next) == 0) { // NULL
-                                       return 0; // NULL
+                                       return false; // NULL
                                }
                                atomic_compare_exchange_strong_explicit(&q->tail,
                                                &tail,
@@ -147,7 +146,7 @@ unsigned int dequeue(queue_t *q)
                                                release, release);
                                thrd_yield();
                        } else {
-                               value = load_32(&q->nodes[get_ptr(next)].value);
+                               *retVal = load_32(&q->nodes[get_ptr(next)].value);
                                success = atomic_compare_exchange_strong_explicit(&q->head,
                                                &head,
                                                MAKE_POINTER(get_ptr(next), get_count(head) + 1),
@@ -158,5 +157,5 @@ unsigned int dequeue(queue_t *q)
                }
        }
        reclaim(get_ptr(head));
-       return value;
+       return true;
 }
index c92e420..edaf3dd 100644 (file)
@@ -27,5 +27,5 @@ typedef struct {
 
 void init_queue(queue_t *q, int num_threads);
 void enqueue(queue_t *q, unsigned int val);
-unsigned int dequeue(queue_t *q);
+bool dequeue(queue_t *q, unsigned int *retVal);
 int get_thread_num();