Edits
[c11tester.git] / waitobj.h
1 #ifndef __WAITOBJ_H__
2 #define __WAITOBJ_H__
3
4 #include "classlist.h"
5 #include "modeltypes.h"
6
7 typedef HashTable<FuncNode *, int, uintptr_t, 0> dist_map_t;
8 typedef HashSet<FuncNode *, uintptr_t, 0> node_set_t;
9 typedef HSIterator<FuncNode *, uintptr_t, 0> node_set_iter;
10
11 class WaitObj {
12 public:
13         WaitObj(thread_id_t);
14         ~WaitObj();
15
16         thread_id_t get_tid() { return tid; }
17
18         void add_waiting_for(thread_id_t other, FuncNode * node, int dist);
19         void add_waited_by(thread_id_t other);
20         bool remove_waiting_for_node(thread_id_t other, FuncNode * node);
21         void remove_waiting_for(thread_id_t other);
22         void remove_waited_by(thread_id_t other);
23
24         thrd_id_set_t * getWaitingFor() { return &waiting_for; }
25         thrd_id_set_t * getWaitedBy() { return &waited_by; }
26
27         node_set_t * getTargetNodes(thread_id_t tid);
28         int lookup_dist(thread_id_t tid, FuncNode * target);
29
30         bool incr_counter(thread_id_t tid);
31
32         void clear_waiting_for();
33
34         void print_waiting_for(bool verbose = false);
35         void print_waited_by();
36
37         SNAPSHOTALLOC
38 private:
39         thread_id_t tid;
40
41         /* The set of threads this thread (tid) is waiting for */
42         thrd_id_set_t waiting_for;
43
44         /* The set of threads waiting for this thread */
45         thrd_id_set_t waited_by;
46
47         SnapVector<dist_map_t *> thrd_dist_maps;
48         SnapVector<node_set_t *> thrd_target_nodes;
49
50         /* Count the number of actions for threads that
51          * this thread is waiting for */
52         SnapVector<uint32_t> thrd_action_counters;
53
54         dist_map_t * getDistMap(thread_id_t tid);
55 };
56
57 #endif