fixed mpmc spec
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 31 Jan 2014 01:40:19 +0000 (17:40 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 31 Jan 2014 01:40:19 +0000 (17:40 -0800)
benchmark/mpmc-queue/mpmc-queue.h

index 627a58b..ee3950d 100644 (file)
@@ -77,10 +77,10 @@ public:
                        }
                @DefineFunc:
                        void show_list() {
-                               model_print("Status:\n");
+                               //model_print("Status:\n");
                                for (int i = 0; i < size(list); i++) {
                                        elem *e = (elem*) elem_at_index(list, i);
-                                       model_print("%d: pos %d, written %d, tid %d, fetch_tid %d, call_id %d\n", i, e->pos, e->written, e->tid, e->fetch_tid, e->id); 
+                                       //model_print("%d: pos %d, written %d, tid %d, fetch_tid %d, call_id %d\n", i, e->pos, e->written, e->tid, e->fetch_tid, e->id); 
                                }
                        }
                @DefineFunc:
@@ -147,26 +147,26 @@ public:
                @DefineFunc:
                        call_id_t prepare_id() {
                                call_id_t res = get_and_inc(tag);
-                               model_print("prepare_id: %d\n", res);
+                               //model_print("prepare_id: %d\n", res);
                                return res;
                        }
                @DefineFunc:
                        bool prepare_check(t_element *pos, thread_id_t tid) {
                                show_list();
                                elem *e = get_elem_by_pos(pos);
-                               model_print("prepare_check: e %d\n", e);
+                               //model_print("prepare_check: e %d\n", e);
                                return NULL == e;
                        }
                @DefineFunc:
                        void prepare(call_id_t id, t_element *pos, thread_id_t tid) {
-                               model_print("prepare: id %d, pos %d, tid %d\n", id, pos, tid);
+                               //model_print("prepare: id %d, pos %d, tid %d\n", id, pos, tid);
                                elem *e = new_elem(pos, id, tid);
                                push_back(list, e);
                        }
                @DefineFunc:
                        call_id_t publish_id(thread_id_t tid) {
                                elem *e = get_elem_by_tid(tid);
-                               model_print("publish_id: id %d\n", e == NULL ? 0 : e->id);
+                               //model_print("publish_id: id %d\n", e == NULL ? 0 : e->id);
                                if (NULL == e)
                                        return DEFAULT_CALL_ID;
                                return e->id;
@@ -175,7 +175,7 @@ public:
                        bool publish_check(thread_id_t tid) {
                                show_list();
                                elem *e = get_elem_by_tid(tid);
-                               model_print("publish_check: tid %d\n", tid);
+                               //model_print("publish_check: tid %d\n", tid);
                                if (NULL == e)
                                        return false;
                                if (elem_num(e->pos) > 1)
@@ -184,14 +184,14 @@ public:
                        }
                @DefineFunc:
                        void publish(thread_id_t tid) {
-                               model_print("publish: tid %d\n", tid);
+                               //model_print("publish: tid %d\n", tid);
                                elem *e = get_elem_by_tid(tid);
                                e->written = true;
                        }
                @DefineFunc:
                        call_id_t fetch_id(t_element *pos) {
                                elem *e = get_elem_by_pos(pos);
-                               model_print("fetch_id: id %d\n", e == NULL ? 0 : e->id);
+                               //model_print("fetch_id: id %d\n", e == NULL ? 0 : e->id);
                                if (NULL == e)
                                        return DEFAULT_CALL_ID;
                                return e->id;
@@ -201,7 +201,7 @@ public:
                                show_list();
                                if (pos == NULL) return true;
                                elem *e = get_elem_by_pos(pos);
-                               model_print("fetch_check: pos %d, e %d\n", pos, e);
+                               //model_print("fetch_check: pos %d, e %d\n", pos, e);
                                if (e == NULL) return false;
                                if (elem_num(e->pos) > 1)
                                        return false;
@@ -211,7 +211,7 @@ public:
                        void fetch(t_element *pos, thread_id_t tid) {
                                if (pos == NULL) return;
                                elem *e = (elem*) get_elem_by_pos(pos);
-                               model_print("fetch: pos %d, tid %d\n", pos, tid);
+                               //model_print("fetch: pos %d, tid %d\n", pos, tid);
                                // Remember the thread that fetches the position
                                e->fetch_tid = tid;
                        }
@@ -219,7 +219,7 @@ public:
                        bool consume_check(thread_id_t tid) {
                                show_list();
                                elem *e = get_elem_by_fetch_tid(tid);
-                               model_print("consume_check: tid %d, e %d\n", tid, e);
+                               //model_print("consume_check: tid %d, e %d\n", tid, e);
                                if (NULL == e)
                                        return false;
                                if (elem_num(e->pos) > 1)
@@ -229,14 +229,14 @@ public:
                @DefineFunc:
                        call_id_t consume_id(thread_id_t tid) {
                                elem *e = get_elem_by_fetch_tid(tid);
-                               model_print("consume_id: id %d\n", e == NULL ? 0 : e->id);
+                               //model_print("consume_id: id %d\n", e == NULL ? 0 : e->id);
                                if (NULL == e)
                                        return DEFAULT_CALL_ID;
                                return e->id;
                        }
                @DefineFunc:
                        void consume(thread_id_t tid) {
-                               model_print("consume: tid %d\n", tid);
+                               //model_print("consume: tid %d\n", tid);
                                int idx = elem_idx_by_fetch_tid(tid);
                                if (idx == -1)
                                        return;
@@ -286,6 +286,12 @@ public:
                        }
                        
                        bool succ = m_rdwr.compare_exchange_weak(rdwr,rdwr+(1<<16),mo_acq_rel);
+                       /**
+                               @Begin
+                               @Commit_point_define_check: succ == true
+                               @Label: Fetch_Succ_Point
+                               @End
+                       */
                        if (succ)
                                break;
                        else
@@ -297,13 +303,6 @@ public:
                while ( (m_written.load(mo_acquire) & 0xFFFF) != wr ) {
                        thrd_yield();
                }
-               /**
-                       @Begin
-                       @Commit_point_define: true
-                       @Potential_commit_point_label: Fetch_Potential_Point 
-                       @Label: Fetch_Succ_Point
-                       @End
-               */
 
                t_element * p = & ( m_array[ rd % t_size ] );
                
@@ -367,8 +366,16 @@ public:
                                */
                                return NULL;
                        }
-
-                       if ( m_rdwr.compare_exchange_weak(rdwr,(rd<<16) | ((wr+1)&0xFFFF),mo_acq_rel) )
+                       
+                       bool succ = m_rdwr.compare_exchange_weak(rdwr,(rd<<16) |
+                               ((wr+1)&0xFFFF),mo_acq_rel);
+                       /**
+                               @Begin
+                               @Commit_point_define_check: succ == true
+                               @Label: Prepare_Succ_Point
+                               @End
+                       */
+                       if (succ)
                                break;
                        else
                                thrd_yield();
@@ -379,13 +386,6 @@ public:
                while ( (m_read.load(mo_acquire) & 0xFFFF) != rd ) {
                        thrd_yield();
                }
-               /**
-                       @Begin
-                       @Commit_point_define: true
-                       @Potential_commit_point_label: Prepare_Potential_Point 
-                       @Label: Prepare_Succ_Point
-                       @End
-               */
 
                t_element * p = & ( m_array[ wr % t_size ] );