changes with lines of spec counted
[cdsspec-compiler.git] / benchmark / ms-queue / my_queue.h
index c92e420657c1847ec3575156be8e6a7b133e2dae..ce6fd0691fb46cb26bb486c775932dbc0ab5c5d2 100644 (file)
@@ -1,5 +1,15 @@
+#ifndef _MY_QUEUE_H
+#define _MY_QUEUE_H
+
 #include <stdatomic.h>
 
+#include <spec_lib.h>
+#include <stdlib.h>
+#include <cdsannotate.h>
+#include <specannotation.h>
+#include <model_memory.h>
+#include "common.h" 
+
 #define MAX_NODES                      0xf
 
 typedef unsigned long long pointer;
@@ -26,6 +36,91 @@ typedef struct {
 } queue_t;
 
 void init_queue(queue_t *q, int num_threads);
+
+/**
+       @Begin
+       @Options:
+               LANG = C;
+       @Global_define:
+               @DeclareStruct:
+               typedef struct tag_elem {
+                       call_id_t id;
+                       unsigned int data;
+               } tag_elem_t;
+               
+               @DeclareVar:
+                       spec_list *__queue;
+                       id_tag_t *tag;
+               @InitVar:
+                       __queue = new_spec_list();
+                       tag = new_id_tag(); // Beginning of available id
+               //@Cleanup:
+               //      if (__queue)
+               //              free_spec_list(__queue);
+               //      if (tag)
+               //              free_id_tag(tag);
+               @DefineFunc:
+                       tag_elem_t* new_tag_elem(call_id_t id, unsigned int data) {
+                               tag_elem_t *e = (tag_elem_t*) CMODEL_MALLOC(sizeof(tag_elem_t));
+                               e->id = id;
+                               e->data = data;
+                               return e;
+                       }
+               //@DefineFunc:
+               //      void free_tag_elem(tag_elem_t *e) {
+               //              free(e);
+               //      }
+               @DefineFunc:
+                       call_id_t get_id(void *wrapper) {
+               //              if (wrapper == NULL)
+               //                      return 0;
+               //              return ((tag_elem_t*) wrapper)->id;
+                               return wrapper == NULL ? 0 : ((tag_elem_t*) wrapper)->id;
+                       }
+               @DefineFunc:
+                       unsigned int get_data(void *wrapper) {
+                               return ((tag_elem_t*) wrapper)->data;
+                       }
+       @Happens_before: Enqueue -> Dequeue
+               # Only check the happens-before relationship according to the id of the
+               # commit_point_set. For commit_point_set that has same ID, A -> B means
+               # B happens after the previous A.
+       @End
+*/
+
+
+
+/**
+       @Begin
+       @Interface: Enqueue
+       @Commit_point_set: Enqueue_Read_Tail | Enqueue_UpdateNext | Enqueue_Additional_Tail_LoadOrCAS
+       @ID: get_and_inc(tag)
+       @Action:
+               # __ID__ is an internal macro that refers to the id of the current
+               # interface call
+               tag_elem_t *elem = new_tag_elem(__ID__, val);
+               push_back(__queue, elem);
+               //model_print("Enqueue: input=%d\n", val);
+       @End
+*/
 void enqueue(queue_t *q, unsigned int val);
-unsigned int dequeue(queue_t *q);
+
+/**
+       @Begin
+       @Interface: Dequeue
+       @Commit_point_set: Dequeue_Read_Head | Dequeue_Read_Tail | Dequeue_LoadNext
+       @ID: get_id(front(__queue))
+       @Action:
+               unsigned int _Old_Val = 0;
+               if (size(__queue) > 0) {
+                       _Old_Val = get_data(front(__queue));
+                       pop_front(__queue);
+               }
+       //      model_print("Dequeue: __RET__=%d, retVal=%d, Old_Val=%d\n", __RET__, *retVal, _Old_Val);
+       @Post_check: _Old_Val == 0 ? !__RET__ : _Old_Val == *retVal
+       @End
+*/
+bool dequeue(queue_t *q, int *retVal);
 int get_thread_num();
+
+#endif