ca733f6738b6235d45158bc8c450749ad7a1d630
[c11tester.git] / funcinst.h
1 #ifndef __FUNCINST_H__
2 #define __FUNCINST_H__
3
4 #include "action.h"
5 #include "hashtable.h"
6 #include "threads-model.h"
7
8 class ModelAction;
9
10 typedef ModelList<FuncInst *> func_inst_list_mt;
11
12 class FuncInst {
13 public:
14         FuncInst(ModelAction *act, FuncNode *func_node);
15         ~FuncInst();
16
17         const char * get_position() const { return position; }
18
19         void * get_location() const { return location; }
20         void set_location(void * loc) { location = loc; }
21
22         action_type get_type() const { return type; }
23         memory_order get_mo() const { return order; }
24         FuncNode * get_func_node() const { return func_node; }
25
26         bool add_pred(FuncInst * other);
27         bool add_succ(FuncInst * other);
28
29         FuncInst * search_in_collision(ModelAction *act);
30         void add_to_collision(FuncInst * inst);
31
32         func_inst_list_mt * get_preds() { return &predecessors; }
33         func_inst_list_mt * get_succs() { return &successors; }
34
35         bool is_read() const;
36         bool is_write() const;
37         bool is_single_location() { return single_location; }
38         void not_single_location() { single_location = false; }
39
40         void set_execution_number(int new_number) { execution_number = new_number; }
41         int get_execution_number() { return execution_number; }
42
43         void set_associated_read(thread_id_t tid, uint64_t read_val, uint32_t marker);
44         uint64_t get_associated_read(thread_id_t tid, uint32_t marker);
45
46         void print();
47
48         MEMALLOC
49 private:
50         const char * position;
51
52         /* Atomic operations with the same source line number may act at different
53          * memory locations, such as the next field of the head pointer in ms-queue.
54          * location only stores the memory location when this FuncInst was constructed.
55          */
56         void * location;
57
58         /* NOTE: for rmw actions, func_inst and act may have different
59          * action types because of action type conversion in ModelExecution */
60         action_type type;
61
62         memory_order order;
63         FuncNode * func_node;
64
65         bool single_location;
66         int execution_number;
67
68         ModelVector<uint64_t> associated_reads;
69         ModelVector<uint32_t> thrd_marker;
70
71         /**
72          * Collisions store a list of FuncInsts with the same position
73          * but different action types. For example,
74          * <code>volatile int x; x++;</code> produces read and write
75          * actions with the same position.
76          */
77         func_inst_list_mt collisions;
78
79         func_inst_list_mt predecessors;
80         func_inst_list_mt successors;
81 };
82
83 #endif  /* __FUNCINST_H__ */