Changeset 19c43b7
- Timestamp:
- Sep 26, 2017, 2:30:51 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- daacf82
- Parents:
- a2d4d1c
- Location:
- src
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
ra2d4d1c r19c43b7 72 72 #define monitor_restore restore( monitors, count, locks, recursions, masks ) 73 73 74 #define blockAndWake( thrd, cnt ) /* Create the necessary information to use the signaller stack */ \75 monitor_save; /* Save monitor states */ \76 BlockInternal( locks, count, thrd, cnt ); /* Everything is ready to go to sleep */ \77 monitor_restore; /* We are back, restore the owners and recursions */ \78 79 74 80 75 //----------------------------------------------------------------------------- … … 229 224 this_thread->monitors.func = func; 230 225 231 LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);226 // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count); 232 227 233 228 // Enter the monitors in order … … 235 230 enter( group ); 236 231 237 LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");232 // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n"); 238 233 } 239 234 … … 241 236 // Dtor for monitor guard 242 237 void ^?{}( monitor_guard_t & this ) { 243 LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);238 // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count); 244 239 245 240 // Leave the monitors in order 246 241 leave( this.m, this.count ); 247 242 248 LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");243 // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n"); 249 244 250 245 // Restore thread context … … 425 420 // block 426 421 void __waitfor_internal( const __waitfor_mask_t & mask, int duration ) { 422 LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal \n"); 423 427 424 // This statment doesn't have a contiguous list of monitors... 428 425 // Create one! … … 431 428 short actual_count = aggregate( mon_storage, mask ); 432 429 433 if(actual_count == 0) return; 430 if(actual_count == 0) { 431 LIB_DEBUG_PRINT_SAFE("Kernel : nothing to wait for \n"); 432 return; 433 } 434 435 LIB_DEBUG_PRINT_SAFE("Kernel : waitfor internal proceeding\n"); 434 436 435 437 // Create storage for monitor context … … 445 447 446 448 if( next ) { 449 *mask.accepted = index; 447 450 if( mask.clauses[index].is_dtor ) { 448 451 #warning case not implemented 449 452 } 450 453 else { 451 blockAndWake( &next, 1 ); 454 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, baton-passing\n"); 455 456 // Create the node specific to this wait operation 457 wait_ctx_primed( this_thread, 0 ); 458 459 // Save monitor states 460 monitor_save; 461 462 // Set the owners to be the next thread 463 set_owner( monitors, count, next ); 464 465 // Everything is ready to go to sleep 466 BlockInternal( locks, count, &next, 1 ); 467 468 // We are back, restore the owners and recursions 469 monitor_restore; 470 471 LIB_DEBUG_PRINT_SAFE("Kernel : thread present, returned\n"); 452 472 } 453 473 454 return index; 474 LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted); 475 476 return; 455 477 } 456 478 } … … 458 480 459 481 if( duration == 0 ) { 482 LIB_DEBUG_PRINT_SAFE("Kernel : non-blocking, exiting\n"); 483 460 484 unlock_all( locks, count ); 485 486 LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted); 461 487 return; 462 488 } … … 465 491 verifyf( duration < 0, "Timeout on waitfor statments not supported yet."); 466 492 493 LIB_DEBUG_PRINT_SAFE("Kernel : blocking waitfor\n"); 494 495 // Create the node specific to this wait operation 496 wait_ctx_primed( this_thread, 0 ); 467 497 468 498 monitor_save; 469 499 set_mask( monitors, count, mask ); 470 500 471 BlockInternal( locks, count ); // Everything is ready to go to sleep 472 //WE WOKE UP 473 monitor_restore; //We are back, restore the masks and recursions 501 //Everything is ready to go to sleep 502 BlockInternal( locks, count ); 503 504 505 // WE WOKE UP 506 507 508 //We are back, restore the masks and recursions 509 monitor_restore; 510 511 LIB_DEBUG_PRINT_SAFE("Kernel : exiting\n"); 512 513 LIB_DEBUG_PRINT_SAFE("Kernel : accepted %d\n", *mask.accepted); 474 514 } 475 515 … … 478 518 479 519 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 480 LIB_DEBUG_PRINT_SAFE("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );520 // LIB_DEBUG_PRINT_SAFE("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 481 521 482 522 //Pass the monitor appropriately … … 559 599 560 600 static inline void lock_all( spinlock ** locks, unsigned short count ) { 601 LIB_DEBUG_ACQUIRE(); 602 LIB_DEBUG_PRINT_NOLOCK("Kernel : Locking"); 561 603 for( int i = 0; i < count; i++ ) { 604 LIB_DEBUG_PRINT_NOLOCK(" %p", locks[i]); 562 605 lock_yield( locks[i] DEBUG_CTX2 ); 563 606 } 607 LIB_DEBUG_PRINT_NOLOCK("\n"); 608 LIB_DEBUG_RELEASE(); 564 609 } 565 610 566 611 static inline void lock_all( monitor_desc ** source, spinlock ** /*out*/ locks, unsigned short count ) { 612 LIB_DEBUG_ACQUIRE(); 613 LIB_DEBUG_PRINT_NOLOCK("Kernel : Locking"); 567 614 for( int i = 0; i < count; i++ ) { 568 615 spinlock * l = &source[i]->lock; 616 LIB_DEBUG_PRINT_NOLOCK(" %p", l); 569 617 lock_yield( l DEBUG_CTX2 ); 570 618 if(locks) locks[i] = l; 571 619 } 620 LIB_DEBUG_PRINT_NOLOCK("\n"); 621 LIB_DEBUG_RELEASE(); 572 622 } 573 623
Note: See TracChangeset
for help on using the changeset viewer.