62141749d5efafc34dc1bbe3fef6656b344571ec
[model-checker.git] / action.h
1 #ifndef __ACTION_H__
2 #define __ACTION_H__
3
4 #include <list>
5 #include <cstddef>
6
7 #include "threads.h"
8 #include "libatomic.h"
9 #include "mymemory.h"
10 #define VALUE_NONE -1
11
12 typedef enum action_type {
13         THREAD_CREATE,
14         THREAD_YIELD,
15         THREAD_JOIN,
16         ATOMIC_READ,
17         ATOMIC_WRITE
18 } action_type_t;
19
20 /* Forward declaration */
21 class Node;
22 class ClockVector;
23
24 class ModelAction {
25 public:
26         ModelAction(action_type_t type, memory_order order, void *loc, int value);
27         ~ModelAction();
28         void print(void);
29
30         thread_id_t get_tid() { return tid; }
31         action_type get_type() { return type; }
32         memory_order get_mo() { return order; }
33         void * get_location() { return location; }
34         int get_seq_number() const { return seq_number; }
35
36         Node * get_node() { return node; }
37         void set_node(Node *n) { node = n; }
38
39         bool is_read();
40         bool is_write();
41         bool is_acquire();
42         bool is_release();
43         bool same_var(ModelAction *act);
44         bool same_thread(ModelAction *act);
45         bool is_dependent(ModelAction *act);
46
47         void create_cv(ModelAction *parent = NULL);
48         void read_from(ModelAction *act);
49
50         inline bool operator <(const ModelAction& act) const {
51                 return get_seq_number() < act.get_seq_number();
52         }
53         inline bool operator >(const ModelAction& act) const {
54                 return get_seq_number() > act.get_seq_number();
55         }
56
57         MEMALLOC
58 private:
59         action_type type;
60         memory_order order;
61         void *location;
62         thread_id_t tid;
63         int value;
64         Node *node;
65         int seq_number;
66
67         ClockVector *cv;
68 };
69
70 typedef std::list<class ModelAction *> action_list_t;
71
72 #endif /* __ACTION_H__ */