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