action: add const qualifier
[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 /**
30  * The ModelAction class encapsulates an atomic action.
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) const;
37
38         thread_id_t get_tid() const { return tid; }
39         action_type get_type() const { return type; }
40         memory_order get_mo() const { return order; }
41         void * get_location() const { return location; }
42         int get_seq_number() const { return seq_number; }
43
44         Node * get_node() const { return node; }
45         void set_node(Node *n) { node = n; }
46
47         bool is_read() const;
48         bool is_write() const;
49         bool is_rmw() const;
50         bool is_acquire() const;
51         bool is_release() const;
52         bool is_seqcst() const;
53         bool same_var(const ModelAction *act) const;
54         bool same_thread(const ModelAction *act) const;
55         bool is_synchronizing(const ModelAction *act) const;
56
57         void create_cv(ModelAction *parent = NULL);
58         ClockVector * get_cv() const { return cv; }
59         void read_from(ModelAction *act);
60
61         bool happens_before(ModelAction *act);
62
63         inline bool operator <(const ModelAction& act) const {
64                 return get_seq_number() < act.get_seq_number();
65         }
66         inline bool operator >(const ModelAction& act) const {
67                 return get_seq_number() > act.get_seq_number();
68         }
69
70         MEMALLOC
71 private:
72
73         /** Type of action (read, write, thread create, thread yield, thread join) */
74         action_type type;
75
76         /** The memory order for this operation. */
77         memory_order order;
78
79         /** A pointer to the memory location for this action. */
80         void *location;
81
82         /** The thread id that performed this action. */
83         thread_id_t tid;
84         
85         /** The value read or written (if RMW, then the value written). This
86          * should probably be something longer. */
87         int value;
88
89         /** A back reference to a Node in NodeStack, if this ModelAction is
90          * saved on the NodeStack. */
91         Node *node;
92         
93         int seq_number;
94
95         /** The clock vector stored with this action; only needed if this
96          * action is a store release? */
97         ClockVector *cv;
98 };
99
100 typedef std::list<class ModelAction *> action_list_t;
101
102 #endif /* __ACTION_H__ */