Changeset 0d4456b
- Timestamp:
- Nov 12, 2020, 11:28:00 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0b996a1
- Parents:
- 6403ae5 (diff), 23954b6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r6403ae5 r0d4456b 96 96 concurrency/exception.hfa \ 97 97 concurrency/kernel.hfa \ 98 concurrency/locks.hfa \ 98 99 concurrency/monitor.hfa \ 99 100 concurrency/mutex.hfa \ -
libcfa/src/concurrency/locks.cfa
r6403ae5 r0d4456b 51 51 } 52 52 53 void ?{}( mutex_lock & this ) {53 void ?{}( single_acquisition_lock & this ) { 54 54 ((blocking_lock &)this){ false, false }; 55 55 } 56 56 57 void ^?{}( mutex_lock & this ) {57 void ^?{}( single_acquisition_lock & this ) { 58 58 // default 59 59 } … … 67 67 } 68 68 69 void ?{}( recursive_mutex_lock & this ) {69 void ?{}( multiple_acquisition_lock & this ) { 70 70 ((blocking_lock &)this){ true, false }; 71 71 } 72 72 73 void ^?{}( recursive_mutex_lock & this ) {73 void ^?{}( multiple_acquisition_lock & this ) { 74 74 // default 75 75 } 76 76 77 77 void lock( blocking_lock & this ) with( this ) { 78 $thread * thrd = active_thread();79 78 lock( lock __cfaabi_dbg_ctx2 ); 80 if ( owner == thrd&& !multi_acquisition) {79 if ( owner == active_thread() && !multi_acquisition) { 81 80 fprintf(stderr, "A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock."); // Possibly throw instead 82 81 exit(EXIT_FAILURE); 83 } else if ( owner != 0p && owner != thrd) {84 append( blocked_threads, thrd);82 } else if ( owner != 0p && owner != active_thread() ) { 83 append( blocked_threads, active_thread() ); 85 84 wait_count++; 86 85 unlock( lock ); 87 86 park( ); 88 } else if ( owner == thrd&& multi_acquisition ) {87 } else if ( owner == active_thread() && multi_acquisition ) { 89 88 recursion_count++; 90 89 unlock( lock ); 91 90 } else { 92 owner = thrd;91 owner = active_thread(); 93 92 recursion_count = 1; 94 93 unlock( lock ); … … 97 96 98 97 bool try_lock( blocking_lock & this ) with( this ) { 99 $thread * thrd = active_thread();100 98 bool ret = false; 101 99 lock( lock __cfaabi_dbg_ctx2 ); 102 100 if ( owner == 0p ) { 103 owner = thrd;104 if ( multi_acquisition )recursion_count = 1;101 owner = active_thread(); 102 recursion_count = 1; 105 103 ret = true; 106 } else if ( owner == thrd&& multi_acquisition ) {104 } else if ( owner == active_thread() && multi_acquisition ) { 107 105 recursion_count++; 108 106 ret = true; … … 115 113 lock( lock __cfaabi_dbg_ctx2 ); 116 114 if ( owner == 0p ){ // no owner implies lock isn't held 117 fprintf( stderr, "There was an attempt to release a lock that isn't held" ); 115 fprintf( stderr, "There was an attempt to release a lock that isn't held" ); 118 116 return; 119 } else if ( strict_owner && active_thread() ) {120 fprintf( stderr, "A thread other than the owner attempted to release an owner lock" ); 117 } else if ( strict_owner && owner != active_thread() ) { 118 fprintf( stderr, "A thread other than the owner attempted to release an owner lock" ); 121 119 return; 122 120 } … … 125 123 $thread * thrd = pop_head( blocked_threads ); 126 124 owner = thrd; 127 recursion_count = ( thrd && multi_acquisition? 1 : 0 );125 recursion_count = ( thrd ? 1 : 0 ); 128 126 wait_count--; 129 127 unpark( thrd ); … … 153 151 } else { 154 152 owner = t; 155 if ( multi_acquisition )recursion_count = 1;153 recursion_count = 1; 156 154 #if !defined( __CFA_NO_STATISTICS__ ) 157 kernelTLS.this_stats = t->curr_cluster->stats;155 //kernelTLS.this_stats = t->curr_cluster->stats; 158 156 #endif 159 157 unpark( t ); … … 165 163 lock( lock __cfaabi_dbg_ctx2 ); 166 164 if ( owner == 0p ){ // no owner implies lock isn't held 167 fprintf( stderr, "A lock that is not held was passed to a synchronization lock" ); 168 } else if ( strict_owner && active_thread() ) {169 fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" ); 165 fprintf( stderr, "A lock that is not held was passed to a synchronization lock" ); 166 } else if ( strict_owner && owner != active_thread() ) { 167 fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" ); 170 168 } else { 171 169 $thread * thrd = pop_head( blocked_threads ); 172 170 owner = thrd; 173 recursion_count = ( thrd && multi_acquisition? 1 : 0 );171 recursion_count = ( thrd ? 1 : 0 ); 174 172 wait_count--; 175 173 unpark( thrd ); … … 184 182 // This is temporary until an inheritance bug is fixed 185 183 186 void lock( mutex_lock & this ){184 void lock( single_acquisition_lock & this ){ 187 185 lock( (blocking_lock &)this ); 188 186 } 189 187 190 void unlock( mutex_lock & this ){188 void unlock( single_acquisition_lock & this ){ 191 189 unlock( (blocking_lock &)this ); 192 190 } 193 191 194 void add_( mutex_lock & this, struct $thread * t ){192 void add_( single_acquisition_lock & this, struct $thread * t ){ 195 193 add_( (blocking_lock &)this, t ); 196 194 } 197 195 198 void remove_( mutex_lock & this ){196 void remove_( single_acquisition_lock & this ){ 199 197 remove_( (blocking_lock &)this ); 200 198 } 201 199 202 void set_recursion_count( mutex_lock & this, size_t recursion ){200 void set_recursion_count( single_acquisition_lock & this, size_t recursion ){ 203 201 set_recursion_count( (blocking_lock &)this, recursion ); 204 202 } 205 203 206 size_t get_recursion_count( mutex_lock & this ){207 get_recursion_count( (blocking_lock &)this );208 } 209 210 void lock( recursive_mutex_lock & this ){204 size_t get_recursion_count( single_acquisition_lock & this ){ 205 return get_recursion_count( (blocking_lock &)this ); 206 } 207 208 void lock( owner_lock & this ){ 211 209 lock( (blocking_lock &)this ); 212 210 } 213 211 214 void unlock( recursive_mutex_lock & this ){212 void unlock( owner_lock & this ){ 215 213 unlock( (blocking_lock &)this ); 216 214 } 217 215 218 void add_( recursive_mutex_lock & this, struct $thread * t ){216 void add_( owner_lock & this, struct $thread * t ){ 219 217 add_( (blocking_lock &)this, t ); 220 218 } 221 219 222 void remove_( recursive_mutex_lock & this ){220 void remove_( owner_lock & this ){ 223 221 remove_( (blocking_lock &)this ); 224 222 } 225 223 226 void set_recursion_count( recursive_mutex_lock & this, size_t recursion ){224 void set_recursion_count( owner_lock & this, size_t recursion ){ 227 225 set_recursion_count( (blocking_lock &)this, recursion ); 228 226 } 229 227 230 size_t get_recursion_count( recursive_mutex_lock & this ){ 231 get_recursion_count( (blocking_lock &)this ); 228 size_t get_recursion_count( owner_lock & this ){ 229 return get_recursion_count( (blocking_lock &)this ); 230 } 231 232 void lock( multiple_acquisition_lock & this ){ 233 lock( (blocking_lock &)this ); 234 } 235 236 void unlock( multiple_acquisition_lock & this ){ 237 unlock( (blocking_lock &)this ); 238 } 239 240 void add_( multiple_acquisition_lock & this, struct $thread * t ){ 241 add_( (blocking_lock &)this, t ); 242 } 243 244 void remove_( multiple_acquisition_lock & this ){ 245 remove_( (blocking_lock &)this ); 246 } 247 248 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ){ 249 set_recursion_count( (blocking_lock &)this, recursion ); 250 } 251 252 size_t get_recursion_count( multiple_acquisition_lock & this ){ 253 return get_recursion_count( (blocking_lock &)this ); 232 254 } 233 255 … … 244 266 info_thread(L) * copy = *i; 245 267 remove( cond->blocked_threads, i ); //remove this thread O(1) 246 cond-> wait_count--;268 cond->count--; 247 269 if( !copy->lock ) { 248 unlock( cond->lock );249 270 #if !defined( __CFA_NO_STATISTICS__ ) 250 #warning unprotected access to tls TODO discuss this 251 kernelTLS.this_stats = copy->t->curr_cluster->stats; 271 //kernelTLS.this_stats = copy->t->curr_cluster->stats; 252 272 #endif 253 273 unpark( copy->t ); … … 285 305 bool ret = !!blocked_threads; 286 306 info_thread(L) * popped = pop_head( blocked_threads ); 287 popped->listed = false;288 307 if(popped != 0p) { 308 popped->listed = false; 289 309 count--; 290 310 if (popped->lock) { … … 303 323 while( blocked_threads ) { 304 324 info_thread(L) * popped = pop_head( blocked_threads ); 305 popped->listed = false;306 325 if(popped != 0p){ 326 popped->listed = false; 307 327 count--; 308 328 if (popped->lock) { … … 341 361 remove_( *i.lock ); 342 362 } 343 363 344 364 unlock( lock ); 345 365 park( ); // blocks here … … 385 405 queue_info_thread( this, i ); 386 406 } 387 407 388 408 void wait( condition_variable(L) & this, Duration duration ) with(this) { 389 409 info_thread( L ) i = { active_thread() }; … … 391 411 } 392 412 393 void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 413 void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 394 414 info_thread( L ) i = { active_thread(), info }; 395 415 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); … … 417 437 queue_info_thread( this, i ); 418 438 } 419 439 420 440 void wait( condition_variable(L) & this, L & l, Duration duration ) with(this) { 421 441 info_thread(L) i = { active_thread() }; … … 423 443 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 424 444 } 425 445 426 446 void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { 427 447 info_thread(L) i = { active_thread(), info }; … … 429 449 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 430 450 } 431 451 432 452 void wait( condition_variable(L) & this, L & l, Time time ) with(this) { 433 453 info_thread(L) i = { active_thread() }; … … 435 455 queue_info_thread_timeout(this, i, time ); 436 456 } 437 457 438 458 void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) { 439 459 info_thread(L) i = { active_thread(), info }; … … 442 462 } 443 463 } 464 465 // thread T1 {}; 466 // thread T2 {}; 467 468 // multiple_acquisition_lock m; 469 // condition_variable( multiple_acquisition_lock ) c; 470 471 // void main( T1 & this ) { 472 // printf("T1 start\n"); 473 // lock(m); 474 // printf("%d\n", counter(c)); 475 // if(empty(c)) { 476 // printf("T1 wait\n"); 477 // wait(c,m,12); 478 // }else{ 479 // printf("%d\n", front(c)); 480 // notify_one(c); 481 // } 482 // unlock(m); 483 // printf("curr thd in main %p \n", active_thread()); 484 // printf("T1 waits for 2s\n"); 485 // lock(m); 486 // wait( c, m, 2`s ); 487 // unlock(m); 488 // printf("T1 wakes\n"); 489 // printf("T1 done\n"); 490 // } 491 492 // void main( T2 & this ) { 493 // printf("T2 start\n"); 494 // lock(m); 495 // printf("%d\n", counter(c)); 496 // if(empty(c)) { 497 // printf("T2 wait\n"); 498 // wait(c,m,12); 499 // }else{ 500 // printf("%d\n", front(c)); 501 // notify_one(c); 502 // } 503 // unlock(m); 504 // printf("T2 done\n"); 505 // } 506 507 // int main() { 508 // printf("start\n"); 509 // processor p[2]; 510 // { 511 // T1 t1; 512 // T2 t2; 513 // } 514 // printf("done\n"); 515 // } -
libcfa/src/concurrency/locks.hfa
r6403ae5 r0d4456b 49 49 //// Blocking Locks 50 50 /////////////////////////////////////////////////////////////////// 51 51 52 struct blocking_lock { 52 53 // Spin lock used for mutual exclusion … … 72 73 }; 73 74 74 struct mutex_lock {75 struct single_acquisition_lock { 75 76 inline blocking_lock; 76 77 }; … … 80 81 }; 81 82 82 struct recursive_mutex_lock {83 struct multiple_acquisition_lock { 83 84 inline blocking_lock; 84 85 }; … … 87 88 void ^?{}( blocking_lock & this ); 88 89 89 void ?{}( mutex_lock & this );90 void ^?{}( mutex_lock & this );90 void ?{}( single_acquisition_lock & this ); 91 void ^?{}( single_acquisition_lock & this ); 91 92 92 93 void ?{}( owner_lock & this ); 93 94 void ^?{}( owner_lock & this ); 94 95 95 void ?{}( recursive_mutex_lock & this );96 void ^?{}( recursive_mutex_lock & this );96 void ?{}( multiple_acquisition_lock & this ); 97 void ^?{}( multiple_acquisition_lock & this ); 97 98 98 99 void lock( blocking_lock & this ); … … 105 106 size_t get_recursion_count( blocking_lock & this ); 106 107 107 void lock( mutex_lock & this );108 void unlock( mutex_lock & this );109 void add_( mutex_lock & this, struct $thread * t );110 void remove_( mutex_lock & this );111 void set_recursion_count( mutex_lock & this, size_t recursion );112 size_t get_recursion_count( mutex_lock & this );108 void lock( single_acquisition_lock & this ); 109 void unlock( single_acquisition_lock & this ); 110 void add_( single_acquisition_lock & this, struct $thread * t ); 111 void remove_( single_acquisition_lock & this ); 112 void set_recursion_count( single_acquisition_lock & this, size_t recursion ); 113 size_t get_recursion_count( single_acquisition_lock & this ); 113 114 114 void lock( recursive_mutex_lock & this ); 115 void unlock( recursive_mutex_lock & this ); 116 void add_( recursive_mutex_lock & this, struct $thread * t ); 117 void remove_( recursive_mutex_lock & this ); 118 void set_recursion_count( recursive_mutex_lock & this, size_t recursion ); 119 size_t get_recursion_count( recursive_mutex_lock & this ); 115 void lock( owner_lock & this ); 116 void unlock( owner_lock & this ); 117 void add_( owner_lock & this, struct $thread * t ); 118 void remove_( owner_lock & this ); 119 void set_recursion_count( owner_lock & this, size_t recursion ); 120 size_t get_recursion_count( owner_lock & this ); 121 122 void lock( multiple_acquisition_lock & this ); 123 void unlock( multiple_acquisition_lock & this ); 124 void add_( multiple_acquisition_lock & this, struct $thread * t ); 125 void remove_( multiple_acquisition_lock & this ); 126 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ); 127 size_t get_recursion_count( multiple_acquisition_lock & this ); 120 128 121 129 /////////////////////////////////////////////////////////////////// -
src/AST/Convert.cpp
r6403ae5 r0d4456b 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Dec 11 21:39:32 201913 // Update Count : 3 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Nov 12 10:07:00 2020 13 // Update Count : 34 14 14 // 15 15 … … 187 187 auto init = get<Initializer>().accept1( node->init ); 188 188 decl->init = init; 189 189 190 190 this->node = decl; 191 191 return nullptr; … … 2812 2812 } 2813 2813 deleteAll(translationUnit); 2814 2815 // Load the local static varables into the global store. 2816 unit.global.sizeType = ast::sizeType; 2817 unit.global.dereference = ast::dereferenceOperator; 2818 unit.global.dtorStruct = ast::dtorStruct; 2819 unit.global.dtorDestroy = ast::dtorStructDestroy; 2820 2814 2821 return unit; 2815 2822 }
Note: See TracChangeset
for help on using the changeset viewer.