3aaa632e8bc2e4ddd6017f3639221867536e9375
[c11tester.git] / waitobj.cc
1 #include "waitobj.h"
2
3 WaitObj::WaitObj(thread_id_t tid) :
4         tid(tid),
5         waiting_for(32),
6         waited_by(32),
7         dist_table(32)
8 {}
9
10 void WaitObj::add_waiting_for(thread_id_t other, int dist)
11 {
12         waiting_for.add(other);
13         dist_table.put(other, dist);
14 }
15
16 void WaitObj::add_waited_by(thread_id_t other)
17 {
18         waited_by.add(other);
19 }
20
21 void WaitObj::remove_waiting_for(thread_id_t other)
22 {
23         waiting_for.remove(other);
24         dist_table.remove(other);
25 }
26
27 void WaitObj::remove_waited_by(thread_id_t other)
28 {
29         waited_by.remove(other);
30 }
31
32 int WaitObj::lookup_dist(thread_id_t other_id)
33 {
34         if (dist_table.contains(other_id))
35                 return dist_table.get(other_id);
36
37         return -1;
38 }
39
40 void WaitObj::reset()
41 {
42         waiting_for.reset();
43         waited_by.reset();
44         dist_table.reset();
45 }
46
47 void WaitObj::print_waiting_for()
48 {
49         if (waiting_for.getSize() == 0)
50                 return;
51
52         model_print("thread %d is waiting for: ", tid);
53         thrd_id_set_iter * it = waiting_for.iterator();
54
55         while (it->hasNext()) {
56                 thread_id_t thread_id = it->next();
57                 model_print("%d ", thread_id);
58         }
59         model_print("\n");
60 }
61
62 void WaitObj::print_waited_by()
63 {
64         if (waited_by.getSize() == 0)
65                 return;
66
67         model_print("thread %d is waited by: ", tid);
68         thrd_id_set_iter * it = waited_by.iterator();
69
70         while (it->hasNext()) {
71                 thread_id_t thread_id = it->next();
72                 model_print("%d ", thread_id);
73         }
74         model_print("\n");
75
76 }