changes
[cdsspec-compiler.git] / benchmark / ms-queue / my_queue.c
index 0d64ed8d168f312fdccae77efe13823a603167d9..50787854561c46a787dfcd0a516b4596693d5591 100644 (file)
@@ -31,7 +31,7 @@ static unsigned int new_node()
                }
        }
        /* free_list is empty? */
-       MODEL_ASSERT(0);
+       //MODEL_ASSERT(0);
        return 0;
 }
 
@@ -42,7 +42,7 @@ static void reclaim(unsigned int node)
        int t = get_thread_num();
 
        /* Don't reclaim NULL node */
-       MODEL_ASSERT(node);
+       //MODEL_ASSERT(node);
 
        for (i = 0; i < MAX_FREELIST; i++) {
                /* Should never race with our own thread here */
@@ -57,7 +57,7 @@ static void reclaim(unsigned int node)
                }
        }
        /* free list is full? */
-       MODEL_ASSERT(0);
+       //MODEL_ASSERT(0);
 }
 
 void init_queue(queue_t *q, int num_threads)
@@ -105,7 +105,7 @@ void enqueue(queue_t *q, unsigned int val)
                tail = atomic_load_explicit(&q->tail, acquire);
                /****FIXME: miss ****/
                next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire);
-               printf("miss1_enqueue\n");
+               //printf("miss1_enqueue\n");
                if (tail == atomic_load_explicit(&q->tail, relaxed)) {
 
                        /* Check for uninitialized 'next' */
@@ -136,9 +136,9 @@ void enqueue(queue_t *q, unsigned int val)
                                succ = atomic_compare_exchange_strong_explicit(&q->tail,
                                                &tail, value, release, relaxed);
                                if (succ) {
-                                       printf("miss2_enqueue CAS succ\n");
+                                       //printf("miss2_enqueue CAS succ\n");
                                }
-                               printf("miss2_enqueue\n");
+                               //printf("miss2_enqueue\n");
                                thrd_yield();
                        }
                }
@@ -156,7 +156,7 @@ void enqueue(queue_t *q, unsigned int val)
        @Interface_define: Dequeue
        @End
 */
-unsigned int dequeue(queue_t *q)
+bool dequeue(queue_t *q, unsigned int *retVal)
 {
        unsigned int value;
        int success = 0;
@@ -167,15 +167,17 @@ unsigned int dequeue(queue_t *q)
        while (!success) {
                /**** detected correctness error ****/
                head = atomic_load_explicit(&q->head, acquire);
+               // FIXME: This must be acquire otherwise we have a bug with 1 enqueue &
+               // 1 dequeue
                tail = atomic_load_explicit(&q->tail, relaxed);
                /****FIXME: miss ****/
                next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire);
-               printf("miss3_dequeue\n");
+               //printf("miss3_dequeue\n");
                if (atomic_load_explicit(&q->head, relaxed) == head) {
                        if (get_ptr(head) == get_ptr(tail)) {
 
                                /* Check for uninitialized 'next' */
-                               MODEL_ASSERT(get_ptr(next) != POISON_IDX);
+                               //MODEL_ASSERT(get_ptr(next) != POISON_IDX);
 
                                if (get_ptr(next) == 0) { // NULL
                                        /**
@@ -184,7 +186,7 @@ unsigned int dequeue(queue_t *q)
                                                @Label: Dequeue_Empty_Point
                                                @End
                                        */
-                                       return 0; // NULL
+                                       return false; // NULL
                                }
                                /****FIXME: miss (not reached) ****/
                                // Second release can be just relaxed
@@ -194,12 +196,12 @@ unsigned int dequeue(queue_t *q)
                                                MAKE_POINTER(get_ptr(next), get_count(tail) + 1),
                                                release, relaxed);
                                if (succ) {
-                                       printf("miss4_dequeue CAS succ\n");
+                                       //printf("miss4_dequeue CAS succ\n");
                                }
-                               printf("miss4_dequeue\n");
+                               //printf("miss4_dequeue\n");
                                thrd_yield();
                        } else {
-                               value = load_32(&q->nodes[get_ptr(next)].value);
+                               *retVal = load_32(&q->nodes[get_ptr(next)].value);
                                //value = q->nodes[get_ptr(next)].value;
                                /****FIXME: correctness error ****/
                                // Seconde release can be just relaxed
@@ -219,5 +221,5 @@ unsigned int dequeue(queue_t *q)
                }
        }
        reclaim(get_ptr(head));
-       return value;
+       return true;
 }