Changeset b1e68d03 for src/libcfa/concurrency
- Timestamp:
- Nov 2, 2017, 11:45:03 AM (8 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:
- 4f748c5
- Parents:
- 85d340d (diff), 0dc954b (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. - Location:
- src/libcfa/concurrency
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r85d340d rb1e68d03 548 548 549 549 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd ); 550 __lib_debug_write( STDERR_FILENO,abort_text, len );550 __lib_debug_write( abort_text, len ); 551 551 552 552 if ( thrd != this_coroutine ) { 553 553 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine ); 554 __lib_debug_write( STDERR_FILENO,abort_text, len );554 __lib_debug_write( abort_text, len ); 555 555 } 556 556 else { 557 __lib_debug_write( STDERR_FILENO,".\n", 2 );557 __lib_debug_write( ".\n", 2 ); 558 558 } 559 559 } -
src/libcfa/concurrency/monitor.c
r85d340d rb1e68d03 21 21 #include "kernel_private.h" 22 22 23 #include "bits/algorithms.h" 24 23 25 //----------------------------------------------------------------------------- 24 26 // Forward declarations … … 95 97 else if( this->owner == thrd) { 96 98 // We already have the monitor, just note how many times we took it 97 verify( this->recursion > 0 );98 99 this->recursion += 1; 99 100 … … 207 208 // it means we don't need to do anything 208 209 if( this->recursion != 0) { 210 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion); 209 211 unlock( &this->lock ); 210 212 return; … … 291 293 292 294 // Sort monitors based on address -> TODO use a sort specialized for small numbers 293 qsort(this.m, count);295 __libcfa_small_sort(this.m, count); 294 296 295 297 // Save previous thread context … … 492 494 set_owner( monitors, count, signallee ); 493 495 496 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", this, signallee ); 497 494 498 //Everything is ready to go to sleep 495 499 BlockInternal( locks, count, &signallee, 1 ); … … 498 502 // WE WOKE UP 499 503 504 505 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : signal_block returned\n" ); 500 506 501 507 //We are back, restore the masks and recursions … … 536 542 short actual_count = aggregate( mon_storage, mask ); 537 543 538 LIB_DEBUG_PRINT_ SAFE("Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max);544 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (short)max); 539 545 540 546 if(actual_count == 0) return; 541 547 542 LIB_DEBUG_PRINT_ SAFE("Kernel : waitfor internal proceeding\n");548 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n"); 543 549 544 550 // Create storage for monitor context … … 556 562 *mask.accepted = index; 557 563 if( mask.clauses[index].is_dtor ) { 558 LIB_DEBUG_PRINT_ SAFE("Kernel : dtor already there\n");564 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n"); 559 565 verifyf( mask.clauses[index].size == 1 , "ERROR: Accepted dtor has more than 1 mutex parameter." ); 560 566 … … 568 574 } 569 575 else { 570 LIB_DEBUG_PRINT_ SAFE("Kernel : thread present, baton-passing\n");576 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n"); 571 577 572 578 // Create the node specific to this wait operation … … 576 582 monitor_save; 577 583 584 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : baton of %d monitors : ", count ); 585 #ifdef __CFA_DEBUG_PRINT__ 586 for( int i = 0; i < count; i++) { 587 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top ); 588 } 589 #endif 590 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n"); 591 578 592 // Set the owners to be the next thread 579 593 set_owner( monitors, count, next ); … … 585 599 monitor_restore; 586 600 587 LIB_DEBUG_PRINT_ SAFE("Kernel : thread present, returned\n");601 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n"); 588 602 } 589 603 590 LIB_DEBUG_PRINT_ SAFE("Kernel : accepted %d\n", *mask.accepted);604 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 591 605 592 606 return; … … 596 610 597 611 if( duration == 0 ) { 598 LIB_DEBUG_PRINT_ SAFE("Kernel : non-blocking, exiting\n");612 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n"); 599 613 600 614 unlock_all( locks, count ); 601 615 602 LIB_DEBUG_PRINT_ SAFE("Kernel : accepted %d\n", *mask.accepted);616 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 603 617 return; 604 618 } … … 607 621 verifyf( duration < 0, "Timeout on waitfor statments not supported yet."); 608 622 609 LIB_DEBUG_PRINT_ SAFE("Kernel : blocking waitfor\n");623 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n"); 610 624 611 625 // Create the node specific to this wait operation … … 629 643 monitor_restore; 630 644 631 LIB_DEBUG_PRINT_ SAFE("Kernel : exiting\n");632 633 LIB_DEBUG_PRINT_ SAFE("Kernel : accepted %d\n", *mask.accepted);645 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n"); 646 647 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted); 634 648 } 635 649 … … 648 662 649 663 static inline void set_owner( monitor_desc ** monitors, short count, thread_desc * owner ) { 650 for( int i = 0; i < count; i++ ) { 651 set_owner( monitors[i], owner ); 664 monitors[0]->owner = owner; 665 monitors[0]->recursion = 1; 666 for( int i = 1; i < count; i++ ) { 667 monitors[i]->owner = owner; 668 monitors[i]->recursion = 0; 652 669 } 653 670 } … … 667 684 static inline thread_desc * next_thread( monitor_desc * this ) { 668 685 //Check the signaller stack 686 LIB_DEBUG_PRINT_SAFE("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); 669 687 __condition_criterion_t * urgent = pop( &this->signal_stack ); 670 688 if( urgent ) { … … 718 736 for(int i = 0; i < count; i++) { 719 737 (criteria[i]){ monitors[i], waiter }; 738 LIB_DEBUG_PRINT_SAFE( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] ); 720 739 push( &criteria[i].target->signal_stack, &criteria[i] ); 721 740 } … … 788 807 } 789 808 790 // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run);809 LIB_DEBUG_PRINT_SAFE( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL ); 791 810 return ready2run ? node->waiting_thread : NULL; 792 811 } … … 856 875 short size = 0; 857 876 for( int i = 0; i < mask.size; i++ ) { 877 __libcfa_small_sort( mask.clauses[i].list, mask.clauses[i].size ); 858 878 for( int j = 0; j < mask.clauses[i].size; j++) { 859 879 insert_unique( storage, size, mask.clauses[i].list[j] ); 860 880 } 861 881 } 862 qsort( storage, size ); 882 // TODO insertion sort instead of this 883 __libcfa_small_sort( storage, size ); 863 884 return size; 864 885 } -
src/libcfa/concurrency/preemption.c
r85d340d rb1e68d03 380 380 381 381 if ( sigaction( sig, &act, NULL ) == -1 ) { 382 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO,382 LIB_DEBUG_PRINT_BUFFER_DECL( 383 383 " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n", 384 384 sig, handler, flags, errno, strerror( errno ) … … 397 397 398 398 if ( sigaction( sig, &act, NULL ) == -1 ) { 399 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO,399 LIB_DEBUG_PRINT_BUFFER_DECL( 400 400 " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n", 401 401 sig, errno, strerror( errno )
Note:
See TracChangeset
for help on using the changeset viewer.