| 1 | #include <mutex_stmt.hfa> | 
|---|
| 2 | #include <locks.hfa> | 
|---|
| 3 |  | 
|---|
| 4 | const unsigned int num_times = 10000; | 
|---|
| 5 |  | 
|---|
| 6 | Duration default_preemption() { return 0; } | 
|---|
| 7 |  | 
|---|
| 8 | single_acquisition_lock m1, m2, m3, m4, m5; | 
|---|
| 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++; | 
|---|
| 17 | mutex ( m1 ) { | 
|---|
| 18 | assert(!insideFlag); | 
|---|
| 19 | insideFlag = true; | 
|---|
| 20 | assert(insideFlag); | 
|---|
| 21 | insideFlag = false; | 
|---|
| 22 | } | 
|---|
| 23 | } | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 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 |  | 
|---|
| 35 | thread T_Multi {}; | 
|---|
| 36 |  | 
|---|
| 37 | void main( T_Multi & this ) { | 
|---|
| 38 | for (unsigned int i = 0; i < num_times; i++) { | 
|---|
| 39 | refTest( m1 ); | 
|---|
| 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 |  | 
|---|
| 73 | single_acquisition_lock l1; | 
|---|
| 74 | exp_backoff_then_block_lock l2; | 
|---|
| 75 | owner_lock l3; | 
|---|
| 76 |  | 
|---|
| 77 | monitor monitor_t {}; | 
|---|
| 78 |  | 
|---|
| 79 | monitor_t l4; | 
|---|
| 80 |  | 
|---|
| 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 ); | 
|---|
| 86 | mutex ( l1, l4 ) { | 
|---|
| 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 | } | 
|---|
| 98 | mutex ( l3, l1, l4 ) { | 
|---|
| 99 | assert(!insideFlag); | 
|---|
| 100 | insideFlag = true; | 
|---|
| 101 | assert(insideFlag); | 
|---|
| 102 | insideFlag = false; | 
|---|
| 103 | } | 
|---|
| 104 | mutex ( l1, l2, l4 ) { | 
|---|
| 105 | assert(!insideFlag); | 
|---|
| 106 | insideFlag = true; | 
|---|
| 107 | assert(insideFlag); | 
|---|
| 108 | insideFlag = false; | 
|---|
| 109 | } | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | int num_tasks = 10; | 
|---|
| 114 | int main() { | 
|---|
| 115 | processor p[num_tasks - 1]; | 
|---|
| 116 |  | 
|---|
| 117 | printf("Start Test: single lock mutual exclusion\n"); | 
|---|
| 118 | { | 
|---|
| 119 | T_Mutex t[num_tasks]; | 
|---|
| 120 | } | 
|---|
| 121 | assert(count == num_tasks * num_times); | 
|---|
| 122 | printf("End Test: single lock mutual exclusion\n"); | 
|---|
| 123 | printf("Start Test: multi lock deadlock/mutual exclusion\n"); | 
|---|
| 124 | { | 
|---|
| 125 | T_Multi t[num_tasks]; | 
|---|
| 126 | } | 
|---|
| 127 | printf("End Test: multi lock deadlock/mutual exclusion\n"); | 
|---|
| 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"); | 
|---|
| 133 | } | 
|---|