Changeset c2b10fa for src/libcfa/concurrency/kernel.c
- Timestamp:
- Jun 7, 2018, 3:03:10 PM (6 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, with_gc
- Children:
- 61accc5
- Parents:
- 61d9b4b (diff), a43c561 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r61d9b4b rc2b10fa 17 17 #include <stddef.h> 18 18 #include <errno.h> 19 #include <string.h> 19 20 extern "C" { 20 21 #include <stdio.h> … … 50 51 thread_desc * mainThread; 51 52 52 struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters; 53 extern "C" { 54 struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters; 55 } 53 56 54 57 //----------------------------------------------------------------------------- … … 150 153 151 154 void ^?{}(processor & this) with( this ){ 152 if( ! do_terminate) {155 if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) { 153 156 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this); 154 157 terminate(&this); 155 verify( this.do_terminate);158 verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 156 159 verify( kernelTLS.this_processor != &this); 157 160 P( terminated ); … … 199 202 200 203 thread_desc * readyThread = NULL; 201 for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ )204 for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ ) 202 205 { 203 206 readyThread = nextThread( this->cltr ); … … 218 221 else 219 222 { 220 spin(this, &spin_count); 223 // spin(this, &spin_count); 224 halt(this); 221 225 } 222 226 } … … 545 549 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 546 550 547 global_clusters.list{ __get };548 global_clusters.lock{};551 __cfa_dbg_global_clusters.list{ __get }; 552 __cfa_dbg_global_clusters.lock{}; 549 553 550 554 // Initialize the main cluster … … 627 631 // When its coroutine terminates, it return control to the mainThread 628 632 // which is currently here 629 mainProcessor->do_terminate = true;633 __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE); 630 634 returnToKernel(); 635 mainThread->self_cor.state = Halted; 631 636 632 637 // THE SYSTEM IS NOW COMPLETELY STOPPED … … 644 649 ^(mainThread){}; 645 650 646 ^( global_clusters.list){};647 ^( global_clusters.lock){};651 ^(__cfa_dbg_global_clusters.list){}; 652 ^(__cfa_dbg_global_clusters.lock){}; 648 653 649 654 __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n"); … … 655 660 656 661 void halt(processor * this) with( *this ) { 662 verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 663 657 664 with( *cltr ) { 658 665 lock (proc_list_lock __cfaabi_dbg_ctx2); … … 664 671 __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this); 665 672 666 verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200); 673 // #ifdef __CFA_WITH_VERIFY__ 674 // int sval = 0; 675 // sem_getvalue(&this->idleLock, &sval); 676 // verifyf(sval < 200, "Binary semaphore reached value %d : \n", sval); 677 // #endif 678 679 verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 667 680 int __attribute__((unused)) ret = sem_wait(&idleLock); 668 verify(ret > 0 || errno == EINTR); 681 // verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno)); 682 683 // wait( idleLock ); 669 684 670 685 __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this); … … 681 696 __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this); 682 697 int __attribute__((unused)) ret = sem_post(&this->idleLock); 683 verify(ret > 0 || errno == EINTR); 684 verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200); 698 // verifyf(ret >= 0 || errno == EINTR, "Sem_post returned %d (errno %d : %s\n", ret, errno, strerror(errno)); 699 700 // #ifdef __CFA_WITH_VERIFY__ 701 // int sval = 0; 702 // sem_getvalue(&this->idleLock, &sval); 703 // verifyf(sval < 200, "Binary semaphore reached value %d\n", sval); 704 // #endif 705 706 // post( this->idleLock ); 685 707 } 686 708 … … 798 820 // Global Queues 799 821 void doregister( cluster & cltr ) { 800 lock ( global_clusters.lock __cfaabi_dbg_ctx2);801 push_front( global_clusters.list, cltr );802 unlock ( global_clusters.lock );822 lock ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2); 823 push_front( __cfa_dbg_global_clusters.list, cltr ); 824 unlock ( __cfa_dbg_global_clusters.lock ); 803 825 } 804 826 805 827 void unregister( cluster & cltr ) { 806 lock ( global_clusters.lock __cfaabi_dbg_ctx2);807 remove( global_clusters.list, cltr );808 unlock( global_clusters.lock );828 lock ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2); 829 remove( __cfa_dbg_global_clusters.list, cltr ); 830 unlock( __cfa_dbg_global_clusters.lock ); 809 831 } 810 832
Note: See TracChangeset
for help on using the changeset viewer.