model: convert 'action_trace' to pointer
[c11tester.git] / model.h
1 #ifndef __MODEL_H__
2 #define __MODEL_H__
3
4 #include <list>
5 #include <map>
6
7 #include "schedule.h"
8 #include "libthreads.h"
9 #include "libatomic.h"
10 #include "threads.h"
11 #include "tree.h"
12
13 #define VALUE_NONE -1
14
15 typedef enum action_type {
16         THREAD_CREATE,
17         THREAD_YIELD,
18         THREAD_JOIN,
19         ATOMIC_READ,
20         ATOMIC_WRITE
21 } action_type_t;
22
23 class ModelAction {
24 public:
25         ModelAction(action_type_t type, memory_order order, void *loc, int value);
26         void print(void);
27
28         thread_id_t get_tid() { return tid; }
29         action_type get_type() { return type; }
30         memory_order get_mo() { return order; }
31         void *get_location() { return location; }
32
33         TreeNode *get_node() { return node; }
34         void set_node(TreeNode *n) { node = n; }
35 private:
36         action_type type;
37         memory_order order;
38         void *location;
39         thread_id_t tid;
40         int value;
41         TreeNode *node;
42 };
43
44 class ModelChecker {
45 public:
46         ModelChecker();
47         ~ModelChecker();
48         class Scheduler *scheduler;
49         Thread *system_thread;
50
51         void add_system_thread(Thread *t);
52
53         void set_current_action(ModelAction *act) { current_action = act; }
54         ModelAction *get_last_conflict(ModelAction *act);
55         void check_current_action(void);
56         void set_backtracking(ModelAction *act);
57         void print_trace(void);
58
59         int add_thread(Thread *t);
60         Thread *get_thread(thread_id_t tid) { return thread_map[tid]; }
61
62         void assign_id(Thread *t);
63
64         int switch_to_master(ModelAction *act);
65 private:
66         int used_thread_id;
67         class ModelAction *current_action;
68         std::list<class ModelAction *> *action_trace;
69         std::map<thread_id_t, class Thread *> thread_map;
70         class TreeNode *rootNode, *currentNode;
71 };
72
73 extern ModelChecker *model;
74
75 int thread_switch_to_master(ModelAction *act);
76
77 #endif /* __MODEL_H__ */