Adding STL stuff and operator news of snapshot to model-checker. Need to actuallly...
[c11tester.git] / action.cc
1 #include <stdio.h>
2
3 #include "model.h"
4 #include "action.h"
5
6 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
7 {
8         Thread *t = thread_current();
9         ModelAction *act = this;
10
11         act->type = type;
12         act->order = order;
13         act->location = loc;
14         act->tid = t->get_id();
15         act->value = value;
16         act->seq_number = model->get_next_seq_num();
17 }
18
19 bool ModelAction::is_read()
20 {
21         return type == ATOMIC_READ;
22 }
23
24 bool ModelAction::is_write()
25 {
26         return type == ATOMIC_WRITE;
27 }
28
29 bool ModelAction::is_acquire()
30 {
31         switch (order) {
32         case memory_order_acquire:
33         case memory_order_acq_rel:
34         case memory_order_seq_cst:
35                 return true;
36         default:
37                 return false;
38         }
39 }
40
41 bool ModelAction::is_release()
42 {
43         switch (order) {
44         case memory_order_release:
45         case memory_order_acq_rel:
46         case memory_order_seq_cst:
47                 return true;
48         default:
49                 return false;
50         }
51 }
52
53 bool ModelAction::same_var(ModelAction *act)
54 {
55         return location == act->location;
56 }
57
58 bool ModelAction::same_thread(ModelAction *act)
59 {
60         return tid == act->tid;
61 }
62
63 bool ModelAction::is_dependent(ModelAction *act)
64 {
65         if (!is_read() && !is_write())
66                 return false;
67         if (!act->is_read() && !act->is_write())
68                 return false;
69         if (same_var(act) && !same_thread(act) &&
70                         (is_write() || act->is_write()))
71                 return true;
72         return false;
73 }
74
75 void ModelAction::print(void)
76 {
77         const char *type_str;
78         switch (this->type) {
79         case THREAD_CREATE:
80                 type_str = "thread create";
81                 break;
82         case THREAD_YIELD:
83                 type_str = "thread yield";
84                 break;
85         case THREAD_JOIN:
86                 type_str = "thread join";
87                 break;
88         case ATOMIC_READ:
89                 type_str = "atomic read";
90                 break;
91         case ATOMIC_WRITE:
92                 type_str = "atomic write";
93                 break;
94         default:
95                 type_str = "unknown type";
96         }
97
98         printf("(%4d) Thread: %d\tAction: %s\tMO: %d\tLoc: %14p\tValue: %d\n",
99                         seq_number, id_to_int(tid), type_str, order, location, value);
100 }