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; }
53 void set_value(int val) { value = val; }
56 bool is_write() const;
58 bool is_initialization() const;
59 bool is_acquire() const;
60 bool is_release() const;
61 bool is_seqcst() const;
62 bool same_var(const ModelAction *act) const;
63 bool same_thread(const ModelAction *act) const;
64 bool is_synchronizing(const ModelAction *act) const;
66 void create_cv(const ModelAction *parent = NULL);
67 ClockVector * get_cv() const { return cv; }
68 void read_from(const ModelAction *act);
70 bool happens_before(const ModelAction *act) const;
72 inline bool operator <(const ModelAction& act) const {
73 return get_seq_number() < act.get_seq_number();
75 inline bool operator >(const ModelAction& act) const {
76 return get_seq_number() > act.get_seq_number();
82 /** Type of action (read, write, thread create, thread yield, thread join) */
85 /** The memory order for this operation. */
88 /** A pointer to the memory location for this action. */
91 /** The thread id that performed this action. */
94 /** The value read or written (if RMW, then the value written). This
95 * should probably be something longer. */
98 /** A back reference to a Node in NodeStack, if this ModelAction is
99 * saved on the NodeStack. */
102 modelclock_t seq_number;
104 /** The clock vector stored with this action; only needed if this
105 * action is a store release? */
109 typedef std::list<ModelAction *> action_list_t;
111 #endif /* __ACTION_H__ */