2 * @brief Models actions taken by threads.
12 #include "libatomic.h"
14 #include "clockvector.h"
18 /** @brief Represents an action type, identifying one of several types of
20 typedef enum action_type {
21 THREAD_CREATE, /**< A thread creation action */
22 THREAD_YIELD, /**< A thread yield action */
23 THREAD_JOIN, /**< A thread join action */
24 ATOMIC_READ, /**< An atomic read action */
25 ATOMIC_WRITE, /**< An atomic write action */
26 ATOMIC_RMW, /**< An atomic read-modify-write action */
27 ATOMIC_INIT /**< Initialization of an atomic object (e.g.,
31 /* Forward declaration */
36 * The ModelAction class encapsulates an atomic action.
40 ModelAction(action_type_t type, memory_order order, void *loc, int value = VALUE_NONE);
42 void print(void) const;
44 thread_id_t get_tid() const { return tid; }
45 action_type get_type() const { return type; }
46 memory_order get_mo() const { return order; }
47 void * get_location() const { return location; }
48 modelclock_t get_seq_number() const { return seq_number; }
49 int get_value() const { return value; }
51 Node * get_node() const { return node; }
52 void set_node(Node *n) { node = n; }
55 bool is_write() const;
57 bool is_initialization() const;
58 bool is_acquire() const;
59 bool is_release() const;
60 bool is_seqcst() const;
61 bool same_var(const ModelAction *act) const;
62 bool same_thread(const ModelAction *act) const;
63 bool is_synchronizing(const ModelAction *act) const;
65 void create_cv(const ModelAction *parent = NULL);
66 ClockVector * get_cv() const { return cv; }
67 void read_from(const ModelAction *act);
69 bool happens_before(const ModelAction *act) const;
71 inline bool operator <(const ModelAction& act) const {
72 return get_seq_number() < act.get_seq_number();
74 inline bool operator >(const ModelAction& act) const {
75 return get_seq_number() > act.get_seq_number();
81 /** Type of action (read, write, thread create, thread yield, thread join) */
84 /** The memory order for this operation. */
87 /** A pointer to the memory location for this action. */
90 /** The thread id that performed this action. */
93 /** The value read or written (if RMW, then the value written). This
94 * should probably be something longer. */
97 /** A back reference to a Node in NodeStack, if this ModelAction is
98 * saved on the NodeStack. */
101 modelclock_t seq_number;
103 /** The clock vector stored with this action; only needed if this
104 * action is a store release? */
108 typedef std::list<ModelAction *> action_list_t;
110 #endif /* __ACTION_H__ */