2 * @brief Models actions taken by threads.
13 #include "clockvector.h"
14 #include "memoryorder.h"
16 using std::memory_order;
17 using std::memory_order_relaxed;
18 using std::memory_order_acquire;
19 using std::memory_order_release;
20 using std::memory_order_acq_rel;
21 using std::memory_order_seq_cst;
23 /** Note that this value can be legitimately used by a program, and
24 hence by iteself does not indicate no value. */
26 #define VALUE_NONE 1234567890
28 /** @brief Represents an action type, identifying one of several types of
30 typedef enum action_type {
31 THREAD_CREATE, /**< A thread creation action */
32 THREAD_START, /**< First action in each thread */
33 THREAD_YIELD, /**< A thread yield action */
34 THREAD_JOIN, /**< A thread join action */
35 THREAD_FINISH, /**< A thread completion action */
36 ATOMIC_READ, /**< An atomic read action */
37 ATOMIC_WRITE, /**< An atomic write action */
38 ATOMIC_RMWR, /**< The read part of an atomic RMW action */
39 ATOMIC_RMW, /**< The write part of an atomic RMW action */
40 ATOMIC_RMWC, /**< Convert an atomic RMW action into a READ */
41 ATOMIC_INIT, /**< Initialization of an atomic object (e.g.,
46 /* Forward declaration */
51 * The ModelAction class encapsulates an atomic action.
55 ModelAction(action_type_t type, memory_order order, void *loc, uint64_t value = VALUE_NONE);
57 void print(void) const;
59 thread_id_t get_tid() const { return tid; }
60 action_type get_type() const { return type; }
61 memory_order get_mo() const { return order; }
62 void * get_location() const { return location; }
63 modelclock_t get_seq_number() const { return seq_number; }
64 uint64_t get_value() const { return value; }
65 const ModelAction * get_reads_from() const { return reads_from; }
67 Node * get_node() const { return node; }
68 void set_node(Node *n) { node = n; }
71 bool is_write() const;
75 bool is_fence() const;
76 bool is_initialization() const;
77 bool is_acquire() const;
78 bool is_release() const;
79 bool is_seqcst() const;
80 bool same_var(const ModelAction *act) const;
81 bool same_thread(const ModelAction *act) const;
82 bool is_synchronizing(const ModelAction *act) const;
84 void create_cv(const ModelAction *parent = NULL);
85 ClockVector * get_cv() const { return cv; }
86 void read_from(const ModelAction *act);
87 void synchronize_with(const ModelAction *act);
89 bool has_synchronized_with(const ModelAction *act) const;
90 bool happens_before(const ModelAction *act) const;
92 inline bool operator <(const ModelAction& act) const {
93 return get_seq_number() < act.get_seq_number();
95 inline bool operator >(const ModelAction& act) const {
96 return get_seq_number() > act.get_seq_number();
99 void process_rmw(ModelAction * act);
100 void copy_typeandorder(ModelAction * act);
105 /** Type of action (read, write, thread create, thread yield, thread join) */
108 /** The memory order for this operation. */
111 /** A pointer to the memory location for this action. */
114 /** The thread id that performed this action. */
117 /** The value written (for write or RMW; undefined for read) */
120 /** The action that this action reads from. Only valid for reads */
121 const ModelAction *reads_from;
123 /** A back reference to a Node in NodeStack, if this ModelAction is
124 * saved on the NodeStack. */
127 modelclock_t seq_number;
129 /** The clock vector stored with this action; only needed if this
130 * action is a store release? */
134 typedef std::list<ModelAction *> action_list_t;
136 #endif /* __ACTION_H__ */