need to fix deque
[cdsspec-compiler.git] / benchmark / ms-queue / my_queue.c
index 232e5d839347794a2056a5c0de5c7e17c6d50811..ae8d2b73d2fc221c5f9f8bc7e29c73ad1841f77e 100644 (file)
@@ -22,14 +22,16 @@ static unsigned int new_node()
        int i;
        int t = get_thread_num();
        for (i = 0; i < MAX_FREELIST; i++) {
-               unsigned int node = load_32(&free_lists[t][i]);
+               //unsigned int node = load_32(&free_lists[t][i]);
+               unsigned int node = free_lists[t][i];
                if (node) {
-                       store_32(&free_lists[t][i], 0);
+                       //store_32(&free_lists[t][i], 0);
+                       free_lists[t][i] = 0;
                        return node;
                }
        }
        /* free_list is empty? */
-       MODEL_ASSERT(0);
+       //MODEL_ASSERT(0);
        return 0;
 }
 
@@ -40,20 +42,22 @@ 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 */
-               unsigned int idx = load_32(&free_lists[t][i]);
+               //unsigned int idx = load_32(&free_lists[t][i]);
+               unsigned int idx = free_lists[t][i];
 
                /* Found empty spot in free list */
                if (idx == 0) {
-                       store_32(&free_lists[t][i], node);
+                       //store_32(&free_lists[t][i], node);
+                       free_lists[t][i] = node;
                        return;
                }
        }
        /* free list is full? */
-       MODEL_ASSERT(0);
+       //MODEL_ASSERT(0);
 }
 
 void init_queue(queue_t *q, int num_threads)
@@ -90,7 +94,8 @@ void enqueue(queue_t *q, unsigned int val)
        pointer tmp;
 
        node = new_node();
-       store_32(&q->nodes[node].value, val);
+       //store_32(&q->nodes[node].value, val);
+       q->nodes[node].value = val;
        tmp = atomic_load_explicit(&q->nodes[node].next, relaxed);
        set_ptr(&tmp, 0); // NULL
        atomic_store_explicit(&q->nodes[node].next, tmp, relaxed);
@@ -101,7 +106,7 @@ void enqueue(queue_t *q, unsigned int val)
                if (tail == atomic_load_explicit(&q->tail, relaxed)) {
 
                        /* Check for uninitialized 'next' */
-                       MODEL_ASSERT(get_ptr(next) != POISON_IDX);
+                       //MODEL_ASSERT(get_ptr(next) != POISON_IDX);
 
                        if (get_ptr(next) == 0) { // == NULL
                                pointer value = MAKE_POINTER(node, get_count(next) + 1);
@@ -151,7 +156,7 @@ unsigned int dequeue(queue_t *q)
                        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
                                        /**
@@ -168,7 +173,8 @@ unsigned int dequeue(queue_t *q)
                                                release, release);
                                thrd_yield();
                        } else {
-                               value = load_32(&q->nodes[get_ptr(next)].value);
+                               //value = load_32(&q->nodes[get_ptr(next)].value);
+                               value = q->nodes[get_ptr(next)].value;
                                success = atomic_compare_exchange_strong_explicit(&q->head,
                                                &head,
                                                MAKE_POINTER(get_ptr(next), get_count(head) + 1),