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