| [a1b41e3] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo | 
|---|
| [206de5a] | 3 | // | 
|---|
| [a1b41e3] | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
|  | 7 | // waitfor.c -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Peter A. Buhr | 
|---|
|  | 10 | // Created On       : Wed Aug 30 17:53:29 2017 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Mon Apr 10 22:52:18 2023 | 
|---|
|  | 13 | // Update Count     : 64 | 
|---|
|  | 14 | // | 
|---|
| [206de5a] | 15 |  | 
|---|
| [73abe95] | 16 | #include <monitor.hfa> | 
|---|
| [9f5ecf5] | 17 |  | 
|---|
|  | 18 | monitor M {}; | 
|---|
|  | 19 |  | 
|---|
| [a1b41e3] | 20 | void notcalled( M & mutex m1, M & mutex m2 ) { | 
|---|
|  | 21 | abort(); | 
|---|
|  | 22 | } | 
|---|
|  | 23 | void or( M & mutex m ) { | 
|---|
|  | 24 | abort(); | 
|---|
|  | 25 | } | 
|---|
|  | 26 | void timeout( M & mutex m ) { | 
|---|
|  | 27 | abort(); | 
|---|
|  | 28 | } | 
|---|
| [9f5ecf5] | 29 |  | 
|---|
| [a1b41e3] | 30 | void fred( M & mutex m, M & mutex or, M & mutex timeout ) { | 
|---|
|  | 31 | // test waitfor and when | 
|---|
| [9f5ecf5] | 32 |  | 
|---|
| [a1b41e3] | 33 | waitfor( notcalled : m, m ); | 
|---|
| [9f5ecf5] | 34 |  | 
|---|
| [a1b41e3] | 35 | waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 36 | } | 
|---|
|  | 37 |  | 
|---|
| [a1b41e3] | 38 | waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 39 | } | 
|---|
| [a1b41e3] | 40 |  | 
|---|
|  | 41 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 42 |  | 
|---|
|  | 43 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 44 | } | 
|---|
|  | 45 |  | 
|---|
| [a1b41e3] | 46 | waitfor( notcalled : m, m ); | 
|---|
|  | 47 | or waitfor( notcalled : m, m ); | 
|---|
|  | 48 |  | 
|---|
|  | 49 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 50 | or when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 51 |  | 
|---|
|  | 52 | waitfor( notcalled : m, m ) { | 
|---|
|  | 53 | } or waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 54 | } | 
|---|
| [a1b41e3] | 55 |  | 
|---|
|  | 56 | waitfor( notcalled : m, m ) { | 
|---|
|  | 57 | } or waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [a1b41e3] | 60 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 61 | } or when( true ) waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 62 | } | 
|---|
| [a1b41e3] | 63 |  | 
|---|
|  | 64 | waitfor( notcalled : m, m ); | 
|---|
|  | 65 | or waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 66 | } | 
|---|
|  | 67 |  | 
|---|
| [a1b41e3] | 68 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 69 | or when( true ) waitfor( notcalled : m, m ) { | 
|---|
| [9f5ecf5] | 70 | } | 
|---|
| [a1b41e3] | 71 |  | 
|---|
|  | 72 | waitfor( notcalled : m, m ) { | 
|---|
|  | 73 | } or waitfor( notcalled : m, m ); | 
|---|
|  | 74 |  | 
|---|
|  | 75 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 76 | } or when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | // test when, waitfor and else | 
|---|
|  | 79 |  | 
|---|
|  | 80 | waitfor( notcalled : m, m ); | 
|---|
|  | 81 | or else; | 
|---|
|  | 82 |  | 
|---|
|  | 83 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 84 | or else; | 
|---|
|  | 85 |  | 
|---|
|  | 86 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 87 | or else; | 
|---|
|  | 88 |  | 
|---|
|  | 89 | waitfor( notcalled : m, m ) { | 
|---|
|  | 90 | } or else { | 
|---|
| [9f5ecf5] | 91 | } | 
|---|
| [a1b41e3] | 92 |  | 
|---|
|  | 93 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 94 | } or else { | 
|---|
| [9f5ecf5] | 95 | } | 
|---|
|  | 96 |  | 
|---|
| [a1b41e3] | 97 | waitfor( notcalled : m, m ); | 
|---|
|  | 98 | or else { | 
|---|
| [9f5ecf5] | 99 | } | 
|---|
| [a1b41e3] | 100 |  | 
|---|
|  | 101 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 102 | or else { | 
|---|
| [9f5ecf5] | 103 | } | 
|---|
| [a1b41e3] | 104 |  | 
|---|
|  | 105 | when( true ) waitfor( notcalled : m, m ); | 
|---|
| [9f5ecf5] | 106 | or else { | 
|---|
|  | 107 | } | 
|---|
|  | 108 |  | 
|---|
| [a1b41e3] | 109 | waitfor( notcalled : m, m ) { | 
|---|
|  | 110 | } or else; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 113 | } or else; | 
|---|
|  | 114 |  | 
|---|
|  | 115 | waitfor( notcalled : m, m ); | 
|---|
|  | 116 | or when( true ) else; | 
|---|
|  | 117 |  | 
|---|
|  | 118 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 119 | or when( true ) else; | 
|---|
|  | 120 |  | 
|---|
|  | 121 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 122 | or when( true ) else; | 
|---|
|  | 123 |  | 
|---|
|  | 124 | waitfor( notcalled : m, m ) { | 
|---|
|  | 125 | } or when( true ) else { | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 129 | } or when( true ) else { | 
|---|
|  | 130 | } | 
|---|
|  | 131 |  | 
|---|
|  | 132 | waitfor( notcalled : m, m ); | 
|---|
|  | 133 | or when( true ) else { | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
|  | 136 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 137 | or when( true ) else { | 
|---|
| [9f5ecf5] | 138 | } | 
|---|
| [a1b41e3] | 139 |  | 
|---|
|  | 140 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 141 | or when( true ) else { | 
|---|
| [9f5ecf5] | 142 | } | 
|---|
| [a1b41e3] | 143 |  | 
|---|
|  | 144 | waitfor( notcalled : m, m ) { | 
|---|
|  | 145 | } or when( true ) else; | 
|---|
|  | 146 |  | 
|---|
|  | 147 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 148 | } or when( true ) else; | 
|---|
|  | 149 |  | 
|---|
|  | 150 | // test when, waitfor and timeout | 
|---|
|  | 151 |  | 
|---|
|  | 152 | waitfor( notcalled : m, m ); | 
|---|
|  | 153 | or timeout( 3 ); | 
|---|
|  | 154 |  | 
|---|
|  | 155 | waitfor( notcalled : m, m ); | 
|---|
|  | 156 | or timeout( 3 ); | 
|---|
|  | 157 |  | 
|---|
|  | 158 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 159 | or timeout( 3 ); | 
|---|
|  | 160 |  | 
|---|
|  | 161 | waitfor( notcalled : m, m ) { | 
|---|
|  | 162 | } or timeout( 3 ) { | 
|---|
| [9f5ecf5] | 163 | } | 
|---|
|  | 164 |  | 
|---|
| [a1b41e3] | 165 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 166 | } or timeout( 3 ) { | 
|---|
| [9f5ecf5] | 167 | } | 
|---|
| [a1b41e3] | 168 |  | 
|---|
|  | 169 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 170 | } or timeout( 3 ) { | 
|---|
| [9f5ecf5] | 171 | } | 
|---|
| [a1b41e3] | 172 |  | 
|---|
|  | 173 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 174 | } or when ( true ) timeout( 3 ) { | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 178 | } or when ( true ) timeout( 3 ) { | 
|---|
|  | 179 | } | 
|---|
|  | 180 |  | 
|---|
|  | 181 | waitfor( notcalled : m, m ); | 
|---|
|  | 182 | or timeout( 3 ) { | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
|  | 185 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 186 | or timeout( 3 ) { | 
|---|
| [9f5ecf5] | 187 | } | 
|---|
| [a1b41e3] | 188 |  | 
|---|
|  | 189 | when( true ) waitfor( notcalled : m, m ); | 
|---|
|  | 190 | or when( true ) timeout( 3 ) { | 
|---|
| [9f5ecf5] | 191 | } | 
|---|
| [a1b41e3] | 192 |  | 
|---|
|  | 193 | waitfor( notcalled : m, m ) { | 
|---|
|  | 194 | } or timeout( 3 ); | 
|---|
|  | 195 |  | 
|---|
|  | 196 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 197 | } or timeout( 3 ); | 
|---|
|  | 198 |  | 
|---|
|  | 199 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 200 | } or when( true ) timeout( 3 ); | 
|---|
|  | 201 |  | 
|---|
|  | 202 | // test when, waitfor, timeout and else | 
|---|
|  | 203 |  | 
|---|
|  | 204 | waitfor( notcalled : m, m ) { | 
|---|
|  | 205 | } or timeout( 3 ) { | 
|---|
|  | 206 | } or when( true ) else {} | 
|---|
|  | 207 |  | 
|---|
|  | 208 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 209 | } or timeout( 3 ) { | 
|---|
|  | 210 | } or when( true ) else {} | 
|---|
|  | 211 |  | 
|---|
|  | 212 | waitfor( notcalled : m, m ) { | 
|---|
|  | 213 | } or timeout( 3 ) { | 
|---|
|  | 214 | } or when( true ) else {} | 
|---|
|  | 215 |  | 
|---|
|  | 216 | waitfor( notcalled : m, m ) { | 
|---|
|  | 217 | } or when( true ) timeout( 3 ) { | 
|---|
|  | 218 | } or when( true ) else {} | 
|---|
|  | 219 |  | 
|---|
|  | 220 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 221 | } or timeout( 3 ) { | 
|---|
|  | 222 | } or when( true ) else {} | 
|---|
|  | 223 |  | 
|---|
|  | 224 | waitfor( notcalled : m, m ) { | 
|---|
|  | 225 | } or when( true ) timeout( 3 ) { | 
|---|
|  | 226 | } or when( true ) else {} | 
|---|
|  | 227 |  | 
|---|
|  | 228 | when( true ) waitfor( notcalled : m, m ) { | 
|---|
|  | 229 | } or when( true ) timeout( 3 ) { | 
|---|
|  | 230 | } or when( true ) else {} | 
|---|
|  | 231 |  | 
|---|
|  | 232 | // test quasi-keywords "or" and "timeout" | 
|---|
|  | 233 |  | 
|---|
|  | 234 | int or = 0, timeout = 0; | 
|---|
|  | 235 | waitfor( timeout : timeout ) timeout += 1; or timeout( timeout ); | 
|---|
|  | 236 | waitfor( notcalled : or, or ) or += 1; or timeout( or ) 3; | 
|---|
|  | 237 | when( or ) waitfor( or : m ) { 4; } or timeout( or ) or += 1; | 
|---|
|  | 238 | when( timeout ) waitfor( notcalled : timeout, timeout ) or += 1; or else timeout += 1; | 
|---|
|  | 239 | when( or + timeout ) waitfor( or : m ) 4; or when( or ) timeout( or ) 4; or when( or ) else timeout += 1; | 
|---|
|  | 240 | when( 3 ) waitfor( or : or ) 3; or when( or ) waitfor( notcalled : or, or ) 4; or else 4; | 
|---|
|  | 241 | when( timeout ) waitfor( or : timeout ) 3; or waitfor( notcalled : timeout, or ) 4; or when( or ) timeout( timeout ) 4; | 
|---|
|  | 242 | when( 3 ) waitfor( or : timeout ) or += 1; | 
|---|
|  | 243 | or waitfor( or : or ) timeout += 1; | 
|---|
|  | 244 | or timeout( timeout ) or += 1; | 
|---|
|  | 245 | or when( 3 ) else or += 1; | 
|---|
|  | 246 |  | 
|---|
|  | 247 | // test else selection | 
|---|
|  | 248 |  | 
|---|
|  | 249 | if ( or > timeout ) waitfor( or : or ) 3; | 
|---|
|  | 250 | else waitfor( timeout : timeout ) 4; | 
|---|
|  | 251 | } | 
|---|
|  | 252 |  | 
|---|
|  | 253 | //Dummy main | 
|---|
|  | 254 | int main( int argc, char const * argv[] ) { | 
|---|
|  | 255 | #pragma GCC warning "Compiled"                      // force non-empty .expect file, NO TABS!!! | 
|---|
| [9f5ecf5] | 256 | } | 
|---|
|  | 257 |  | 
|---|
| [a1b41e3] | 258 | // Local Variables: // | 
|---|
|  | 259 | // tab-width: 4 // | 
|---|
|  | 260 | // compile-command: "cfa waitfor.cfa" // | 
|---|
|  | 261 | // End: // | 
|---|