2 * @brief Models actions taken by threads.
12 #include "libatomic.h"
14 #include "clockvector.h"
16 /** Note that this value can be legitimately used by a program, and
17 hence by iteself does not indicate no value. */
19 #define VALUE_NONE 1234567890
21 /** @brief Represents an action type, identifying one of several types of
23 typedef enum action_type {
24 THREAD_CREATE, /**< A thread creation action */
25 THREAD_START, /**< First action in each thread */
26 THREAD_YIELD, /**< A thread yield action */
27 THREAD_JOIN, /**< A thread join action */
28 ATOMIC_READ, /**< An atomic read action */
29 ATOMIC_WRITE, /**< An atomic write action */
30 ATOMIC_RMW, /**< An atomic read-modify-write action */
31 ATOMIC_INIT /**< Initialization of an atomic object (e.g.,
35 /* Forward declaration */
40 * The ModelAction class encapsulates an atomic action.
44 ModelAction(action_type_t type, memory_order order, void *loc, uint64_t value = VALUE_NONE);
46 void print(void) const;
48 thread_id_t get_tid() const { return tid; }
49 action_type get_type() const { return type; }
50 memory_order get_mo() const { return order; }
51 void * get_location() const { return location; }
52 modelclock_t get_seq_number() const { return seq_number; }
53 uint64_t get_value() const { return value; }
54 const ModelAction * get_reads_from() const { return reads_from; }
56 Node * get_node() const { return node; }
57 void set_node(Node *n) { node = n; }
60 bool is_write() const;
62 bool is_initialization() const;
63 bool is_acquire() const;
64 bool is_release() const;
65 bool is_seqcst() const;
66 bool same_var(const ModelAction *act) const;
67 bool same_thread(const ModelAction *act) const;
68 bool is_synchronizing(const ModelAction *act) const;
70 void create_cv(const ModelAction *parent = NULL);
71 ClockVector * get_cv() const { return cv; }
72 void read_from(const ModelAction *act);
74 bool happens_before(const ModelAction *act) const;
76 inline bool operator <(const ModelAction& act) const {
77 return get_seq_number() < act.get_seq_number();
79 inline bool operator >(const ModelAction& act) const {
80 return get_seq_number() > act.get_seq_number();
83 void upgrade_rmw(ModelAction * act);
88 /** Type of action (read, write, thread create, thread yield, thread join) */
91 /** The memory order for this operation. */
94 /** A pointer to the memory location for this action. */
97 /** The thread id that performed this action. */
100 /** The value written (for write or RMW; undefined for read) */
103 /** The action that this action reads from. Only valid for reads */
104 const ModelAction *reads_from;
106 /** A back reference to a Node in NodeStack, if this ModelAction is
107 * saved on the NodeStack. */
110 modelclock_t seq_number;
112 /** The clock vector stored with this action; only needed if this
113 * action is a store release? */
117 typedef std::list<ModelAction *> action_list_t;
119 #endif /* __ACTION_H__ */