edits
[cdsspec-compiler.git] / benchmark / chase-lev-deque-bugfix / deque.h
index 837df898e421b8a8f038dd5d0c4dd1fd59b2b1ba..82560f18947d28024928e04af8df6cecef11a240 100644 (file)
@@ -26,52 +26,23 @@ typedef struct {
     @Options:
         LANG = C;
     @Global_define:
-        @DeclareStruct:
-        typedef struct tag_elem {
-            call_id_t id;
-            int data;
-        } tag_elem_t;
-        
         @DeclareVar:
-        spec_list *__deque;
-        id_tag_t *tag;
+                       IntegerList *__deque;
         @InitVar:
-            __deque = new_spec_list();
-                       //model_print("init_list\n");
-            tag = new_id_tag(); // Beginning of available id
-               //@Cleanup:
-                       //if (__deque) {
-                               //free_spec_list(__deque);
-                               //model_print("free_list\n");
-                       //}
-                       //if (tag)
-                               //free_id_tag(tag);
-        @DefineFunc:
-            tag_elem_t* new_tag_elem(call_id_t id, int data) {
-                tag_elem_t *e = (tag_elem_t*) CMODEL_MALLOC(sizeof(tag_elem_t));
-                e->id = id;
-                e->data = data;
-                return e;
-            }
-        @DefineFunc:
-            call_id_t get_id(void *wrapper) {
-                               //tag_elem_t *res = (tag_elem_t*) wrapper;
-                               return res == NULL ? 0 : ((tag_elem_t*) wrapper)->id;
-                               //if (res == NULL) {
-                                       //model_print("wrong id here\n");
-                                       //return 0;
-                               //}
-                //return res->id;
-            }
-        @DefineFunc:
-            int get_data(void *wrapper) {
-                               //tag_elem_t *res = (tag_elem_t*) wrapper;
-                //return res->data;
-                               return ((tag_elem_t*) wrapper)->data;
-            }
+                       __deque = createIntegerList();
+               @Finalize:
+                       if (__deque)
+                               destroyIntegerList(__deque);
+                       return true;
+               @DefineFunc:
+                       bool succ(int res) {
+                               return res != EMPTY && res != ABORT;
+                       }
     @Happens_before:
         Push -> Steal
-               Push -> Take
+       @Commutativity: Push <-> Steal: true
+       @Commutativity: Take <-> Steal: true
+
     @End
 */
 
@@ -82,16 +53,16 @@ void resize(Deque *q);
 /**
     @Begin
     @Interface: Take 
-    //@Commit_point_set: Take_Read_Bottom | Take_CAS_Top | Take_Additional_Point
     @Commit_point_set: Take_Read_Bottom | Take_Additional_Point
-    @ID: __RET__ == EMPTY ? DEFAULT_CALL_ID : get_id(back(__deque))
+    @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID
     @Action:
-        int _Old_Val = EMPTY;
-               if (__RET__ != EMPTY && size(__deque) > 0) {
-                       _Old_Val = get_data(back(__deque));
-               pop_back(__deque);
+               int elem = 0;
+       if (succ(__RET__)) {
+                       elem = back(__deque);
+                       pop_back(__deque);
+                       //model_print("take: elem=%d, __RET__=%d\n", elem, __RET__);
                }
-    @Post_check: _Old_Val == __RET__
+    @Post_check: succ(__RET__) ? __RET__ == elem : true
     @End
 */
 int take(Deque *q);
@@ -100,8 +71,10 @@ int take(Deque *q);
     @Begin
     @Interface: Push 
     @Commit_point_set: Push_Update_Bottom 
-    @ID: get_and_inc(tag);
-    @Action: push_back(__deque, new_tag_elem(__ID__, x));
+    @ID: x 
+    @Action:
+               push_back(__deque, x);
+               //model_print("push: elem=%d\n", x);
     @End
 */
 void push(Deque *q, int x);
@@ -109,17 +82,16 @@ void push(Deque *q, int x);
 /**
     @Begin
     @Interface: Steal 
-    //@Commit_point_set: Steal_Read_Bottom | Steal_CAS_Top | Steal_Additional_Point
     @Commit_point_set: Steal_Read_Bottom | Steal_Additional_Point
-    @ID: (__RET__ == EMPTY || __RET__ == ABORT) ? DEFAULT_CALL_ID : get_id(front(__deque))
+    @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID
     @Action:
-        int _Old_Val = EMPTY;
-               if (__RET__ != EMPTY && __RET__ != ABORT && size(__deque) > 0) {
-                       _Old_Val = get_data(front(__deque));
+       int elem = 0;
+       if (succ(__RET__)) {
+                       elem = front(__deque);
                        pop_front(__deque);
+                       //model_print("steal: elem=%d, __RET__=%d\n", elem, __RET__);
                }
-    @Post_check:
-        _Old_Val == __RET__ || __RET__ == EMPTY || __RET__ == ABORT
+    @Post_check: succ(__RET__) ? __RET__ == elem : true
     @End
 */
 int steal(Deque *q);