1) Add more comments.
[c11tester.git] / action.h
1 /** @file action.h
2  *  @brief Models actions taken by threads.
3  */
4
5 #ifndef __ACTION_H__
6 #define __ACTION_H__
7
8 #include <list>
9 #include <cstddef>
10
11 #include "threads.h"
12 #include "libatomic.h"
13 #include "mymemory.h"
14 #define VALUE_NONE -1
15
16 typedef enum action_type {
17         THREAD_CREATE,
18         THREAD_YIELD,
19         THREAD_JOIN,
20         ATOMIC_READ,
21         ATOMIC_WRITE,
22         ATOMIC_RMW
23 } action_type_t;
24
25 /* Forward declaration */
26 class Node;
27 class ClockVector;
28 /**
29  * The ModelAction class encapsulates an atomic action.
30  */
31
32 class ModelAction {
33 public:
34         ModelAction(action_type_t type, memory_order order, void *loc, int value);
35         ~ModelAction();
36         void print(void);
37
38         thread_id_t get_tid() { return tid; }
39         action_type get_type() { return type; }
40         memory_order get_mo() { return order; }
41         void * get_location() { return location; }
42         int get_seq_number() const { return seq_number; }
43
44         Node * get_node() { return node; }
45         void set_node(Node *n) { node = n; }
46
47         bool is_read();
48         bool is_write();
49         bool is_rmw();
50         bool is_acquire();
51         bool is_release();
52         bool is_seqcst();
53         bool same_var(ModelAction *act);
54         bool same_thread(ModelAction *act);
55         bool is_synchronizing(ModelAction *act);
56
57         void create_cv(ModelAction *parent = NULL);
58         void read_from(ModelAction *act);
59
60         inline bool operator <(const ModelAction& act) const {
61                 return get_seq_number() < act.get_seq_number();
62         }
63         inline bool operator >(const ModelAction& act) const {
64                 return get_seq_number() > act.get_seq_number();
65         }
66
67         MEMALLOC
68 private:
69
70         /** Type of action (read, write, thread create, thread yield, thread join) */
71         action_type type;
72
73         /** The memory order for this operation. */
74         memory_order order;
75
76         /** A pointer to the memory location for this action. */
77         void *location;
78
79         /** The thread id that performed this action. */
80         thread_id_t tid;
81         
82         /** The value written.  This should probably be something longer. */
83         int value;
84
85         Node *node;
86         
87         int seq_number;
88
89         /** The clock vector stored with this action if this action is a
90          *  store release */
91
92         ClockVector *cv;
93 };
94
95 typedef std::list<class ModelAction *> action_list_t;
96
97 #endif /* __ACTION_H__ */