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_START, /**< First action in each thread */
23 THREAD_YIELD, /**< A thread yield action */
24 THREAD_JOIN, /**< A thread join action */
25 ATOMIC_READ, /**< An atomic read action */
26 ATOMIC_WRITE, /**< An atomic write action */
27 ATOMIC_RMW, /**< An atomic read-modify-write action */
28 ATOMIC_INIT /**< Initialization of an atomic object (e.g.,
32 /* Forward declaration */
37 * The ModelAction class encapsulates an atomic action.
41 ModelAction(action_type_t type, memory_order order, void *loc, int value = VALUE_NONE);
43 void print(void) const;
45 thread_id_t get_tid() const { return tid; }
46 action_type get_type() const { return type; }
47 memory_order get_mo() const { return order; }
48 void * get_location() const { return location; }
49 modelclock_t get_seq_number() const { return seq_number; }
50 int get_value() const { return value; }
51 const ModelAction * get_reads_from() const { return reads_from; }
53 Node * get_node() const { return node; }
54 void set_node(Node *n) { node = n; }
57 bool is_write() const;
59 bool is_initialization() const;
60 bool is_acquire() const;
61 bool is_release() const;
62 bool is_seqcst() const;
63 bool same_var(const ModelAction *act) const;
64 bool same_thread(const ModelAction *act) const;
65 bool is_synchronizing(const ModelAction *act) const;
67 void create_cv(const ModelAction *parent = NULL);
68 ClockVector * get_cv() const { return cv; }
69 void read_from(const ModelAction *act);
71 bool happens_before(const ModelAction *act) const;
73 inline bool operator <(const ModelAction& act) const {
74 return get_seq_number() < act.get_seq_number();
76 inline bool operator >(const ModelAction& act) const {
77 return get_seq_number() > act.get_seq_number();
83 /** Type of action (read, write, thread create, thread yield, thread join) */
86 /** The memory order for this operation. */
89 /** A pointer to the memory location for this action. */
92 /** The thread id that performed this action. */
95 /** The value read or written (if RMW, then the value written). This
96 * should probably be something longer. */
99 /** The action that this action reads from. Only valid for reads */
100 const ModelAction *reads_from;
102 /** A back reference to a Node in NodeStack, if this ModelAction is
103 * saved on the NodeStack. */
106 modelclock_t seq_number;
108 /** The clock vector stored with this action; only needed if this
109 * action is a store release? */
113 typedef std::list<ModelAction *> action_list_t;
115 #endif /* __ACTION_H__ */