34c174289731368c0f9233c2bf275ee4288c3ab4
[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(thread_id_t other, FuncNode * node);
21         void remove_waited_by(thread_id_t other);
22
23         thrd_id_set_t * getWaitingFor() { return &waiting_for; }
24         thrd_id_set_t * getWaitedBy() { return &waited_by; }
25
26         node_set_t * getTargetNodes(thread_id_t tid);
27         int lookup_dist(thread_id_t tid, FuncNode * target);
28         int lookup_dist(thread_id_t other_tid);
29         void clear_waiting_for();
30
31         void print_waiting_for(bool verbose = false);
32         void print_waited_by();
33
34         SNAPSHOTALLOC
35 private:
36         thread_id_t tid;
37
38         /* The set of threads this thread (tid) is waiting for */
39         thrd_id_set_t waiting_for;
40
41         /* The set of threads waiting for this thread */
42         thrd_id_set_t waited_by;
43
44         SnapVector<dist_map_t *> thrd_dist_maps;
45         SnapVector<node_set_t *> thrd_target_nodes;
46
47         dist_map_t * getDistMap(thread_id_t tid);
48 };
49
50 #endif