- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r1805b1b r27f5f71 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Dec 1 17:52:57201913 // Update Count : 4512 // Last Modified On : Fri Nov 29 17:59:16 2019 13 // Update Count : 35 14 14 // 15 15 … … 41 41 //----------------------------------------------------------------------------- 42 42 // Some assembly required 43 #if defined( __i386 )43 #if defined( __i386 ) 44 44 #define CtxGet( ctx ) \ 45 45 __asm__ volatile ( \ … … 124 124 125 125 extern "C" { 126 struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;126 struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters; 127 127 } 128 128 … … 132 132 // Global state 133 133 thread_local struct KernelThreadData kernelTLS __attribute__ ((tls_model ( "initial-exec" ))) = { 134 NULL, // cannot use 0p134 NULL, 135 135 NULL, 136 136 { NULL, 1, false, false }, … … 141 141 // Struct to steal stack 142 142 struct current_stack_info_t { 143 __stack_t * storage; // pointer to stack object144 void * base;// base of stack145 void * limit;// stack grows towards stack limit146 void * context;// address of cfa_context_t143 __stack_t * storage; // pointer to stack object 144 void *base; // base of stack 145 void *limit; // stack grows towards stack limit 146 void *context; // address of cfa_context_t 147 147 }; 148 148 … … 173 173 name = "Main Thread"; 174 174 state = Start; 175 starter = 0p;176 last = 0p;177 cancellation = 0p;175 starter = NULL; 176 last = NULL; 177 cancellation = NULL; 178 178 } 179 179 … … 186 186 self_mon.recursion = 1; 187 187 self_mon_p = &self_mon; 188 next = 0p;189 190 node.next = 0p;191 node.prev = 0p;188 next = NULL; 189 190 node.next = NULL; 191 node.prev = NULL; 192 192 doregister(curr_cluster, this); 193 193 … … 213 213 terminated{ 0 }; 214 214 do_terminate = false; 215 preemption_alarm = 0p;215 preemption_alarm = NULL; 216 216 pending_preemption = false; 217 217 runner.proc = &this; … … 233 233 } 234 234 235 pthread_join( kernel_thread, 0p);235 pthread_join( kernel_thread, NULL ); 236 236 free( this.stack ); 237 237 } … … 280 280 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); 281 281 282 thread_desc * readyThread = 0p;282 thread_desc * readyThread = NULL; 283 283 for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ ) 284 284 { … … 412 412 processor * proc = (processor *) arg; 413 413 kernelTLS.this_processor = proc; 414 kernelTLS.this_thread = 0p;414 kernelTLS.this_thread = NULL; 415 415 kernelTLS.preemption_state.[enabled, disable_count] = [false, 1]; 416 416 // SKULLDUGGERY: We want to create a context for the processor coroutine … … 425 425 426 426 //Set global state 427 kernelTLS.this_thread = 0p;427 kernelTLS.this_thread = NULL; 428 428 429 429 //We now have a proper context from which to schedule threads … … 441 441 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, &proc->runner); 442 442 443 return 0p; 444 } 445 446 static void Abort( int ret, const char * func ) { 447 if ( ret ) { 448 abort( "%s : internal error, error(%d) %s.", func, ret, strerror( ret ) ); 449 } // if 450 } // Abort 451 452 void * create_pthread( pthread_t * pthread, void * (*start)(void *), void * arg ) { 453 pthread_attr_t attr; 454 455 Abort( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 456 457 #ifdef __CFA_DEBUG__ 458 size_t guardsize; 459 Abort( pthread_attr_getguardsize( &attr, &guardsize ), "pthread_attr_getguardsize" ); 460 Abort( pthread_attr_setguardsize( &attr, guardsize ), "pthread_attr_setguardsize" ); 461 #endif 462 463 size_t stacksize; 464 Abort( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" ); // default stack size, normally defined by shell limit 465 assert( stacksize >= PTHREAD_STACK_MIN ); 466 void * stack = malloc( stacksize ); 467 Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 468 469 Abort( pthread_create( pthread, &attr, start, arg ), "pthread_create" ); 470 return stack; 443 return NULL; 471 444 } 472 445 … … 474 447 __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this); 475 448 476 this->stack = create_pthread( &this->kernel_thread, CtxInvokeProcessor, (void *)this ); 449 pthread_attr_t attr; 450 int ret; 451 ret = pthread_attr_init( &attr ); // initialize attribute 452 if ( ret ) { 453 abort( "%s : internal error, pthread_attr_init failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 454 } // if 455 456 size_t stacksize; 457 ret = pthread_attr_getstacksize( &attr, &stacksize ); // default stack size, normally defined by shell limit 458 if ( ret ) { 459 abort( "%s : internal error, pthread_attr_getstacksize failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 460 } // if 461 assert( stacksize >= PTHREAD_STACK_MIN ); 462 463 this->stack = malloc( stacksize ); 464 ret = pthread_attr_setstack( &attr, this->stack, stacksize ); 465 if ( ret ) { 466 abort( "%s : internal error, pthread_attr_setstack failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 467 } // if 468 469 ret = pthread_create( &this->kernel_thread, &attr, CtxInvokeProcessor, (void *)this ); 470 if ( ret ) { 471 abort( "%s : internal error, pthread_create failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 472 } // if 473 // pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this ); 477 474 478 475 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); … … 531 528 verify( ! kernelTLS.preemption_state.enabled ); 532 529 533 verifyf( thrd->next == 0p, "Expected null got %p", thrd->next );530 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 534 531 535 532 with( *thrd->curr_cluster ) { … … 710 707 void ?{}(processorCtx_t & this, processor * proc) { 711 708 (this.__cor){ "Processor" }; 712 this.__cor.starter = 0p;709 this.__cor.starter = NULL; 713 710 this.proc = proc; 714 711 } … … 719 716 terminated{ 0 }; 720 717 do_terminate = false; 721 preemption_alarm = 0p;718 preemption_alarm = NULL; 722 719 pending_preemption = false; 723 720 kernel_thread = pthread_self(); … … 913 910 914 911 void V(semaphore & this) with( this ) { 915 thread_desc * thrd = 0p;912 thread_desc * thrd = NULL; 916 913 lock( lock __cfaabi_dbg_ctx2 ); 917 914 count += 1;
Note:
See TracChangeset
for help on using the changeset viewer.