@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");
+ __deque = createIntegerList();
+ @Finalize:
+ if (__deque)
+ destroyIntegerList(__deque);
+ return true;
+ @DefineFunc:
+ bool succ(int res) {
+ return res != EMPTY && res != ABORT;
}
- 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;
- 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;
- }
@Happens_before:
Push -> Steal
- Push -> Take
+ @Commutativity: Push <-> Steal: true
+ @Commutativity: Take <-> Steal: true
+ @Commutativity: Steal <-> Steal: _Method1.__RET__ == ABORT || _Method2.__RET__ == ABORT
+
@End
*/
/**
@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))
+ @Commit_point_set: TakeReadBottom | TakeReadBuffer | TakeReadTop
+ @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID
@Action:
- int _Old_Val = EMPTY;
- if (__RET__ != EMPTY) {
- if (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);
/**
@Begin
@Interface: Push
- @Commit_point_set: Push_Update_Bottom
- @ID: get_and_inc(tag);
+ @Commit_point_set: PushUpdateBuffer
+ @ID: x
@Action:
- tag_elem_t *elem = new_tag_elem(__ID__, x);
- push_back(__deque, elem);
+ push_back(__deque, x);
+ //model_print("push: elem=%d\n", x);
@End
*/
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))
+ @Commit_point_set: StealReadTop1 | StealReadTop2 | StealReadBuffer
+ @ID: succ(__RET__) ? __RET__ : DEFAULT_CALL_ID
@Action:
- int _Old_Val = EMPTY;
- if (__RET__ != EMPTY && __RET__ != ABORT) {
- if (size(__deque) > 0) {
- _Old_Val = get_data(front(__deque));
- pop_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);