1 | #include <mutex_stmt.hfa> |
---|
2 | #include <locks.hfa> |
---|
3 | #include <stats.hfa> |
---|
4 | |
---|
5 | const unsigned int num_times = 10000; |
---|
6 | |
---|
7 | Duration default_preemption() { return 0; } |
---|
8 | |
---|
9 | single_acquisition_lock m1, m2, m3, m4, m5; |
---|
10 | |
---|
11 | thread T_Mutex {}; |
---|
12 | bool insideFlag = false; |
---|
13 | int count = 0; |
---|
14 | |
---|
15 | void main( T_Mutex & this ) { |
---|
16 | for (unsigned int i = 0; i < num_times; i++) { |
---|
17 | mutex ( m1 ) count++; |
---|
18 | mutex ( m1 ) { |
---|
19 | assert(!insideFlag); |
---|
20 | insideFlag = true; |
---|
21 | assert(insideFlag); |
---|
22 | insideFlag = false; |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | void refTest( single_acquisition_lock & m ) { |
---|
28 | mutex ( m ) { |
---|
29 | assert(!insideFlag); |
---|
30 | insideFlag = true; |
---|
31 | assert(insideFlag); |
---|
32 | insideFlag = false; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | thread T_Multi {}; |
---|
37 | |
---|
38 | void main( T_Multi & this ) { |
---|
39 | for (unsigned int i = 0; i < num_times; i++) { |
---|
40 | refTest( m1 ); |
---|
41 | mutex ( m1 ) { |
---|
42 | assert(!insideFlag); |
---|
43 | insideFlag = true; |
---|
44 | assert(insideFlag); |
---|
45 | insideFlag = false; |
---|
46 | } |
---|
47 | mutex ( m1, m2, m3, m4, m5 ) { |
---|
48 | assert(!insideFlag); |
---|
49 | insideFlag = true; |
---|
50 | assert(insideFlag); |
---|
51 | insideFlag = false; |
---|
52 | } |
---|
53 | mutex ( m3, m1 ) { |
---|
54 | assert(!insideFlag); |
---|
55 | insideFlag = true; |
---|
56 | assert(insideFlag); |
---|
57 | insideFlag = false; |
---|
58 | } |
---|
59 | mutex ( m1, m2, m4 ) { |
---|
60 | assert(!insideFlag); |
---|
61 | insideFlag = true; |
---|
62 | assert(insideFlag); |
---|
63 | insideFlag = false; |
---|
64 | } |
---|
65 | mutex ( m1, m3, m4, m5 ) { |
---|
66 | assert(!insideFlag); |
---|
67 | insideFlag = true; |
---|
68 | assert(insideFlag); |
---|
69 | insideFlag = false; |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | single_acquisition_lock l1; |
---|
75 | linear_backoff_then_block_lock l2; |
---|
76 | owner_lock l3; |
---|
77 | |
---|
78 | thread T_Multi_Poly {}; |
---|
79 | |
---|
80 | void main( T_Multi_Poly & this ) { |
---|
81 | for (unsigned int i = 0; i < num_times; i++) { |
---|
82 | refTest( l1 ); |
---|
83 | mutex ( l1 ) { |
---|
84 | assert(!insideFlag); |
---|
85 | insideFlag = true; |
---|
86 | assert(insideFlag); |
---|
87 | insideFlag = false; |
---|
88 | } |
---|
89 | mutex ( l1, l2, l3 ) { |
---|
90 | assert(!insideFlag); |
---|
91 | insideFlag = true; |
---|
92 | assert(insideFlag); |
---|
93 | insideFlag = false; |
---|
94 | } |
---|
95 | mutex ( l3, l1 ) { |
---|
96 | assert(!insideFlag); |
---|
97 | insideFlag = true; |
---|
98 | assert(insideFlag); |
---|
99 | insideFlag = false; |
---|
100 | } |
---|
101 | mutex ( l1, l2 ) { |
---|
102 | assert(!insideFlag); |
---|
103 | insideFlag = true; |
---|
104 | assert(insideFlag); |
---|
105 | insideFlag = false; |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | int num_tasks = 10; |
---|
111 | int main() { |
---|
112 | processor p[num_tasks - 1]; |
---|
113 | |
---|
114 | printf("Start Test: single lock mutual exclusion\n"); |
---|
115 | { |
---|
116 | T_Mutex t[num_tasks]; |
---|
117 | } |
---|
118 | assert(count == num_tasks * num_times); |
---|
119 | printf("End Test: single lock mutual exclusion\n"); |
---|
120 | printf("Start Test: multi lock deadlock/mutual exclusion\n"); |
---|
121 | { |
---|
122 | T_Multi t[num_tasks]; |
---|
123 | } |
---|
124 | printf("End Test: multi lock deadlock/mutual exclusion\n"); |
---|
125 | printf("Start Test: multi polymorphic lock deadlock/mutual exclusion\n"); |
---|
126 | { |
---|
127 | T_Multi_Poly t[num_tasks]; |
---|
128 | } |
---|
129 | printf("End Test: multi polymorphic lock deadlock/mutual exclusion\n"); |
---|
130 | } |
---|