model: create 'action_list_t' typedef
[model-checker.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 typedef std::list<class ModelAction *> action_list_t;
24
25 class ModelAction {
26 public:
27         ModelAction(action_type_t type, memory_order order, void *loc, int value);
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
35         TreeNode *get_node() { return node; }
36         void set_node(TreeNode *n) { node = n; }
37 private:
38         action_type type;
39         memory_order order;
40         void *location;
41         thread_id_t tid;
42         int value;
43         TreeNode *node;
44 };
45
46 class ModelChecker {
47 public:
48         ModelChecker();
49         ~ModelChecker();
50         class Scheduler *scheduler;
51         Thread *system_thread;
52
53         void add_system_thread(Thread *t);
54
55         void set_current_action(ModelAction *act) { current_action = act; }
56         ModelAction *get_last_conflict(ModelAction *act);
57         void check_current_action(void);
58         void set_backtracking(ModelAction *act);
59         void print_trace(void);
60
61         int add_thread(Thread *t);
62         Thread *get_thread(thread_id_t tid) { return thread_map[tid]; }
63
64         void assign_id(Thread *t);
65
66         int switch_to_master(ModelAction *act);
67 private:
68         int used_thread_id;
69         class ModelAction *current_action;
70         action_list_t *action_trace;
71         std::map<thread_id_t, class Thread *> thread_map;
72         class TreeNode *rootNode, *currentNode;
73 };
74
75 extern ModelChecker *model;
76
77 int thread_switch_to_master(ModelAction *act);
78
79 #endif /* __MODEL_H__ */