Changeset 36982fc for src/libcfa/concurrency
- Timestamp:
- Nov 29, 2017, 2:50:33 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:
- 875a72f
- Parents:
- 8a0a64d9
- Location:
- src/libcfa/concurrency
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r8a0a64d9 r36982fc 110 110 } 111 111 112 LIB_DEBUG_DO( bool validate( alarm_list_t * this ) {112 __cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) { 113 113 alarm_node_t ** it = &this->head; 114 114 while( (*it) ) { … … 186 186 187 187 disable_interrupts(); 188 lock( event_kernel->lock DEBUG_CTX2 );188 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 189 189 { 190 190 verify( validate( alarms ) ); … … 198 198 unlock( event_kernel->lock ); 199 199 this->set = true; 200 enable_interrupts( DEBUG_CTX);200 enable_interrupts( __cfaabi_dbg_ctx ); 201 201 } 202 202 203 203 void unregister_self( alarm_node_t * this ) { 204 204 disable_interrupts(); 205 lock( event_kernel->lock DEBUG_CTX2 );205 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 206 206 { 207 207 verify( validate( &event_kernel->alarms ) ); … … 209 209 } 210 210 unlock( event_kernel->lock ); 211 enable_interrupts( DEBUG_CTX);211 enable_interrupts( __cfaabi_dbg_ctx ); 212 212 this->set = false; 213 213 } -
src/libcfa/concurrency/coroutine.c
r8a0a64d9 r36982fc 76 76 void ^?{}(coStack_t & this) { 77 77 if ( ! this.userStack && this.storage ) { 78 LIB_DEBUG_DO(78 __cfaabi_dbg_debug_do( 79 79 if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) { 80 80 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); … … 131 131 132 132 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment 133 LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );134 LIB_NO_DEBUG_DO( this->storage = malloc( cxtSize + this->size + 8 ) );133 __cfaabi_dbg_debug_do( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) ); 134 __cfaabi_dbg_no_debug_do( this->storage = malloc( cxtSize + this->size + 8 ) ); 135 135 136 LIB_DEBUG_DO(136 __cfaabi_dbg_debug_do( 137 137 if ( mprotect( this->storage, pageSize, PROT_NONE ) == -1 ) { 138 138 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) ); … … 144 144 } // if 145 145 146 LIB_DEBUG_DO( this->limit = (char *)this->storage + pageSize );147 LIB_NO_DEBUG_DO( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment146 __cfaabi_dbg_debug_do( this->limit = (char *)this->storage + pageSize ); 147 __cfaabi_dbg_no_debug_do( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment 148 148 149 149 } else { -
src/libcfa/concurrency/invoke.c
r8a0a64d9 r36982fc 31 31 extern void __leave_thread_monitor( struct thread_desc * this ); 32 32 extern void disable_interrupts(); 33 extern void enable_interrupts( DEBUG_CTX_PARAM);33 extern void enable_interrupts( __cfaabi_dbg_ctx_param ); 34 34 35 35 void CtxInvokeCoroutine( 36 37 38 36 void (*main)(void *), 37 struct coroutine_desc *(*get_coroutine)(void *), 38 void *this 39 39 ) { 40 // LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);40 struct coroutine_desc* cor = get_coroutine( this ); 41 41 42 struct coroutine_desc* cor = get_coroutine( this ); 42 if(cor->state == Primed) { 43 __suspend_internal(); 44 } 43 45 44 if(cor->state == Primed) { 45 __suspend_internal(); 46 } 46 cor->state = Active; 47 47 48 cor->state = Active;48 main( this ); 49 49 50 main( this );50 cor->state = Halted; 51 51 52 cor->state = Halted; 53 54 //Final suspend, should never return 55 __leave_coroutine(); 56 abortf("Resumed dead coroutine"); 52 //Final suspend, should never return 53 __leave_coroutine(); 54 abortf("Resumed dead coroutine"); 57 55 } 58 56 59 57 void CtxInvokeThread( 60 61 62 63 58 void (*dtor)(void *), 59 void (*main)(void *), 60 struct thread_desc *(*get_thread)(void *), 61 void *this 64 62 ) { 65 66 67 63 // First suspend, once the thread arrives here, 64 // the function pointer to main can be invalidated without risk 65 __suspend_internal(); 68 66 69 70 67 // Fetch the thread handle from the user defined thread structure 68 struct thread_desc* thrd = get_thread( this ); 71 69 72 73 enable_interrupts( DEBUG_CTX);70 // Officially start the thread by enabling preemption 71 enable_interrupts( __cfaabi_dbg_ctx ); 74 72 75 76 73 // Call the main of the thread 74 main( this ); 77 75 78 79 80 81 82 83 84 85 86 76 // To exit a thread we must : 77 // 1 - Mark it as halted 78 // 2 - Leave its monitor 79 // 3 - Disable the interupts 80 // 4 - Final suspend 81 // The order of these 4 operations is very important 82 //Final suspend, should never return 83 __leave_thread_monitor( thrd ); 84 abortf("Resumed dead thread"); 87 85 } 88 86 89 87 90 88 void CtxStart( 91 92 93 94 89 void (*main)(void *), 90 struct coroutine_desc *(*get_coroutine)(void *), 91 void *this, 92 void (*invoke)(void *) 95 93 ) { 96 // LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p) to invoke (%p) from start (%p)\n", this, main, invoke, CtxStart); 97 98 struct coStack_t* stack = &get_coroutine( this )->stack; 94 struct coStack_t* stack = &get_coroutine( this )->stack; 99 95 100 96 #if defined( __i386__ ) … … 103 99 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 104 100 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 105 101 uint16_t fcw; // X97 FPU control word (preserved across function calls) 106 102 void *rturn; // where to go on return from uSwitch 107 103 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke … … 116 112 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this; // argument to invoke 117 113 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 118 119 114 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 115 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 120 116 121 117 #elif defined( __x86_64__ ) 122 118 123 124 125 126 127 128 129 119 struct FakeStack { 120 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15 121 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 122 uint16_t fcw; // X97 FPU control word (preserved across function calls) 123 void *rturn; // where to go on return from uSwitch 124 void *dummyReturn; // NULL return address to provide proper alignment 125 }; 130 126 131 132 127 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack ); 128 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp 133 129 134 135 136 137 138 139 130 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; 131 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub; 132 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this; 133 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke; 134 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 135 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 140 136 #else 141 137 #error Only __i386__ and __x86_64__ is supported for threads in cfa 142 138 #endif 143 139 } -
src/libcfa/concurrency/kernel.c
r8a0a64d9 r36982fc 150 150 151 151 this.runner = &runner; 152 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);152 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner); 153 153 runner{ &this }; 154 154 } … … 156 156 void ^?{}(processor & this) { 157 157 if( ! this.do_terminate ) { 158 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);158 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this); 159 159 this.do_terminate = true; 160 160 P( this.terminated ); … … 181 181 processor * this = runner.proc; 182 182 183 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);183 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this); 184 184 185 185 { … … 187 187 preemption_scope scope = { this }; 188 188 189 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);189 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); 190 190 191 191 thread_desc * readyThread = NULL; … … 213 213 } 214 214 215 LIB_DEBUG_PRINT_SAFE("Kernel : core %p stopping\n", this);215 __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this); 216 216 } 217 217 218 218 V( this->terminated ); 219 219 220 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);220 __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this); 221 221 } 222 222 … … 292 292 processorCtx_t proc_cor_storage = { proc, &info }; 293 293 294 LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);294 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 295 295 296 296 //Set global state … … 299 299 300 300 //We now have a proper context from which to schedule threads 301 LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);301 __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx); 302 302 303 303 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 310 310 311 311 // Main routine of the core returned, the core is now fully terminated 312 LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);312 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner); 313 313 314 314 return NULL; … … 316 316 317 317 void start(processor * this) { 318 LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);318 __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this); 319 319 320 320 pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this ); 321 321 322 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);322 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); 323 323 } 324 324 … … 334 334 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 335 335 336 lock( this_processor->cltr->ready_queue_lock DEBUG_CTX2 );336 lock( this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 ); 337 337 append( this_processor->cltr->ready_queue, thrd ); 338 338 unlock( this_processor->cltr->ready_queue_lock ); … … 343 343 thread_desc * nextThread(cluster * this) { 344 344 verify( disable_preempt_count > 0 ); 345 lock( this->ready_queue_lock DEBUG_CTX2 );345 lock( this->ready_queue_lock __cfaabi_dbg_ctx2 ); 346 346 thread_desc * head = pop_head( this->ready_queue ); 347 347 unlock( this->ready_queue_lock ); … … 355 355 suspend(); 356 356 verify( disable_preempt_count > 0 ); 357 enable_interrupts( DEBUG_CTX);357 enable_interrupts( __cfaabi_dbg_ctx ); 358 358 } 359 359 … … 367 367 verify( disable_preempt_count > 0 ); 368 368 369 enable_interrupts( DEBUG_CTX);369 enable_interrupts( __cfaabi_dbg_ctx ); 370 370 } 371 371 … … 381 381 verify( disable_preempt_count > 0 ); 382 382 383 enable_interrupts( DEBUG_CTX);383 enable_interrupts( __cfaabi_dbg_ctx ); 384 384 } 385 385 … … 395 395 verify( disable_preempt_count > 0 ); 396 396 397 enable_interrupts( DEBUG_CTX);397 enable_interrupts( __cfaabi_dbg_ctx ); 398 398 } 399 399 … … 408 408 verify( disable_preempt_count > 0 ); 409 409 410 enable_interrupts( DEBUG_CTX);410 enable_interrupts( __cfaabi_dbg_ctx ); 411 411 } 412 412 … … 423 423 verify( disable_preempt_count > 0 ); 424 424 425 enable_interrupts( DEBUG_CTX);425 enable_interrupts( __cfaabi_dbg_ctx ); 426 426 } 427 427 … … 441 441 // Kernel boot procedures 442 442 void kernel_startup(void) { 443 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");443 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 444 444 445 445 // Start by initializing the main thread … … 450 450 (*mainThread){ &info }; 451 451 452 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");452 __cfaabi_dbg_print_safe("Kernel : Main thread ready\n"); 453 453 454 454 // Initialize the main cluster … … 456 456 (*mainCluster){}; 457 457 458 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");458 __cfaabi_dbg_print_safe("Kernel : main cluster ready\n"); 459 459 460 460 // Initialize the main processor and the main processor ctx … … 483 483 484 484 // THE SYSTEM IS NOW COMPLETELY RUNNING 485 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");486 487 enable_interrupts( DEBUG_CTX);485 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 486 487 enable_interrupts( __cfaabi_dbg_ctx ); 488 488 } 489 489 490 490 void kernel_shutdown(void) { 491 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");491 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 492 492 493 493 disable_interrupts(); … … 513 513 ^(mainThread){}; 514 514 515 LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");515 __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n"); 516 516 } 517 517 … … 523 523 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 524 524 // the globalAbort flag is true. 525 lock( kernel_abort_lock DEBUG_CTX2 );525 lock( kernel_abort_lock __cfaabi_dbg_ctx2 ); 526 526 527 527 // first task to abort ? … … 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( abort_text, len );550 __cfaabi_dbg_bits_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( abort_text, len );554 __cfaabi_dbg_bits_write( abort_text, len ); 555 555 } 556 556 else { 557 __ lib_debug_write( ".\n", 2 );557 __cfaabi_dbg_bits_write( ".\n", 2 ); 558 558 } 559 559 } 560 560 561 561 extern "C" { 562 void __ lib_debug_acquire() {563 lock( kernel_debug_lock DEBUG_CTX2 );564 } 565 566 void __ lib_debug_release() {562 void __cfaabi_dbg_bits_acquire() { 563 lock( kernel_debug_lock __cfaabi_dbg_ctx2 ); 564 } 565 566 void __cfaabi_dbg_bits_release() { 567 567 unlock( kernel_debug_lock ); 568 568 } … … 582 582 583 583 void P(semaphore & this) { 584 lock( this.lock DEBUG_CTX2 );584 lock( this.lock __cfaabi_dbg_ctx2 ); 585 585 this.count -= 1; 586 586 if ( this.count < 0 ) { … … 598 598 void V(semaphore & this) { 599 599 thread_desc * thrd = NULL; 600 lock( this.lock DEBUG_CTX2 );600 lock( this.lock __cfaabi_dbg_ctx2 ); 601 601 this.count += 1; 602 602 if ( this.count <= 0 ) { -
src/libcfa/concurrency/kernel_private.h
r8a0a64d9 r36982fc 30 30 void disable_interrupts(); 31 31 void enable_interrupts_noPoll(); 32 void enable_interrupts( DEBUG_CTX_PARAM);32 void enable_interrupts( __cfaabi_dbg_ctx_param ); 33 33 } 34 34 … … 39 39 disable_interrupts(); 40 40 ScheduleThread( thrd ); 41 enable_interrupts( DEBUG_CTX);41 enable_interrupts( __cfaabi_dbg_ctx ); 42 42 } 43 43 thread_desc * nextThread(cluster * this); -
src/libcfa/concurrency/monitor.c
r8a0a64d9 r36982fc 91 91 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 92 92 // Lock the monitor spinlock 93 DO_LOCK( this->lock DEBUG_CTX2 );93 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 94 94 thread_desc * thrd = this_thread; 95 95 96 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);96 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 97 97 98 98 if( !this->owner ) { … … 100 100 set_owner( this, thrd ); 101 101 102 LIB_DEBUG_PRINT_SAFE("Kernel : mon is free \n");102 __cfaabi_dbg_print_safe("Kernel : mon is free \n"); 103 103 } 104 104 else if( this->owner == thrd) { … … 106 106 this->recursion += 1; 107 107 108 LIB_DEBUG_PRINT_SAFE("Kernel : mon already owned \n");108 __cfaabi_dbg_print_safe("Kernel : mon already owned \n"); 109 109 } 110 110 else if( is_accepted( this, group) ) { … … 115 115 reset_mask( this ); 116 116 117 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts \n");117 __cfaabi_dbg_print_safe("Kernel : mon accepts \n"); 118 118 } 119 119 else { 120 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n");120 __cfaabi_dbg_print_safe("Kernel : blocking \n"); 121 121 122 122 // Some one else has the monitor, wait in line for it … … 124 124 BlockInternal( &this->lock ); 125 125 126 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this);126 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this); 127 127 128 128 // BlockInternal will unlock spinlock, no need to unlock ourselves … … 130 130 } 131 131 132 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered mon %p\n", thrd, this);132 __cfaabi_dbg_print_safe("Kernel : %10p Entered mon %p\n", thrd, this); 133 133 134 134 // Release the lock and leave … … 139 139 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 140 140 // Lock the monitor spinlock 141 DO_LOCK( this->lock DEBUG_CTX2 );141 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 142 142 thread_desc * thrd = this_thread; 143 143 144 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);144 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner); 145 145 146 146 147 147 if( !this->owner ) { 148 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this);148 __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this); 149 149 150 150 // No one has the monitor, just take it … … 164 164 __monitor_group_t group = { &this, 1, func }; 165 165 if( is_accepted( this, group) ) { 166 LIB_DEBUG_PRINT_SAFE("Kernel : mon accepts dtor, block and signal it \n");166 __cfaabi_dbg_print_safe("Kernel : mon accepts dtor, block and signal it \n"); 167 167 168 168 // Wake the thread that is waiting for this … … 183 183 } 184 184 else { 185 LIB_DEBUG_PRINT_SAFE("Kernel : blocking \n");185 __cfaabi_dbg_print_safe("Kernel : blocking \n"); 186 186 187 187 wait_ctx( this_thread, 0 ) … … 196 196 } 197 197 198 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this);198 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this); 199 199 200 200 } … … 203 203 void __leave_monitor_desc( monitor_desc * this ) { 204 204 // Lock the monitor spinlock, DO_LOCK to reduce contention 205 DO_LOCK( this->lock DEBUG_CTX2 );206 207 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);205 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 206 207 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); 208 208 209 209 verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this ); … … 215 215 // it means we don't need to do anything 216 216 if( this->recursion != 0) { 217 LIB_DEBUG_PRINT_SAFE("Kernel : recursion still %d\n", this->recursion);217 __cfaabi_dbg_print_safe("Kernel : recursion still %d\n", this->recursion); 218 218 unlock( this->lock ); 219 219 return; … … 232 232 // Leave single monitor for the last time 233 233 void __leave_dtor_monitor_desc( monitor_desc * this ) { 234 LIB_DEBUG_DO(234 __cfaabi_dbg_debug_do( 235 235 if( this_thread != this->owner ) { 236 236 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner); … … 249 249 250 250 // Lock the monitor now 251 DO_LOCK( this->lock DEBUG_CTX2 );251 DO_LOCK( this->lock __cfaabi_dbg_ctx2 ); 252 252 253 253 disable_interrupts(); … … 308 308 (this_thread->monitors){m, count, func}; 309 309 310 // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);310 // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count); 311 311 312 312 // Enter the monitors in order … … 314 314 enter( group ); 315 315 316 // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");316 // __cfaabi_dbg_print_safe("MGUARD : entered\n"); 317 317 } 318 318 … … 320 320 // Dtor for monitor guard 321 321 void ^?{}( monitor_guard_t & this ) { 322 // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);322 // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count); 323 323 324 324 // Leave the monitors in order 325 325 leave( this.m, this.count ); 326 326 327 // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");327 // __cfaabi_dbg_print_safe("MGUARD : left\n"); 328 328 329 329 // Restore thread context … … 430 430 431 431 //Some more checking in debug 432 LIB_DEBUG_DO(432 __cfaabi_dbg_debug_do( 433 433 thread_desc * this_thrd = this_thread; 434 434 if ( this.monitor_count != this_thrd->monitors.size ) { … … 487 487 set_owner( monitors, count, signallee ); 488 488 489 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );489 __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee ); 490 490 491 491 //Everything is ready to go to sleep … … 496 496 497 497 498 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : signal_block returned\n" );498 __cfaabi_dbg_print_buffer_local( "Kernel : signal_block returned\n" ); 499 499 500 500 //We are back, restore the masks and recursions … … 535 535 __lock_size_t actual_count = aggregate( mon_storage, mask ); 536 536 537 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);537 __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max); 538 538 539 539 if(actual_count == 0) return; 540 540 541 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");541 __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n"); 542 542 543 543 // Create storage for monitor context … … 556 556 __acceptable_t& accepted = mask[index]; 557 557 if( accepted.is_dtor ) { 558 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");558 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n"); 559 559 verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." ); 560 560 … … 568 568 } 569 569 else { 570 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");570 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n"); 571 571 572 572 // Create the node specific to this wait operation … … 576 576 monitor_save; 577 577 578 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : baton of %d monitors : ", count );578 __cfaabi_dbg_print_buffer_local( "Kernel : baton of %d monitors : ", count ); 579 579 #ifdef __CFA_DEBUG_PRINT__ 580 580 for( int i = 0; i < count; i++) { 581 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );581 __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top ); 582 582 } 583 583 #endif 584 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");584 __cfaabi_dbg_print_buffer_local( "\n"); 585 585 586 586 // Set the owners to be the next thread … … 593 593 monitor_restore; 594 594 595 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");595 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n"); 596 596 } 597 597 598 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);598 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 599 599 return; 600 600 } … … 603 603 604 604 if( duration == 0 ) { 605 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");605 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n"); 606 606 607 607 unlock_all( locks, count ); 608 608 609 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);609 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 610 610 return; 611 611 } … … 614 614 verifyf( duration < 0, "Timeout on waitfor statments not supported yet."); 615 615 616 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");616 __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n"); 617 617 618 618 // Create the node specific to this wait operation … … 636 636 monitor_restore; 637 637 638 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");639 640 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);638 __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n"); 639 640 __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted); 641 641 } 642 642 … … 645 645 646 646 static inline void set_owner( monitor_desc * this, thread_desc * owner ) { 647 // LIB_DEBUG_PRINT_SAFE("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );647 // __cfaabi_dbg_print_safe("Kernal : Setting owner of %p to %p ( was %p)\n", this, owner, this->owner ); 648 648 649 649 //Pass the monitor appropriately … … 677 677 static inline thread_desc * next_thread( monitor_desc * this ) { 678 678 //Check the signaller stack 679 LIB_DEBUG_PRINT_SAFE("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top);679 __cfaabi_dbg_print_safe("Kernel : mon %p AS-stack top %p\n", this, this->signal_stack.top); 680 680 __condition_criterion_t * urgent = pop( this->signal_stack ); 681 681 if( urgent ) { … … 729 729 for( __lock_size_t i = 0; i < count; i++) { 730 730 (criteria[i]){ monitors[i], waiter }; 731 LIB_DEBUG_PRINT_SAFE( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] );731 __cfaabi_dbg_print_safe( "Kernel : target %p = %p\n", criteria[i].target, &criteria[i] ); 732 732 push( criteria[i].target->signal_stack, &criteria[i] ); 733 733 } … … 738 738 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 739 739 for( __lock_size_t i = 0; i < count; i++ ) { 740 DO_LOCK( *locks[i] DEBUG_CTX2 );740 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 ); 741 741 } 742 742 } … … 745 745 for( __lock_size_t i = 0; i < count; i++ ) { 746 746 __spinlock_t * l = &source[i]->lock; 747 DO_LOCK( *l DEBUG_CTX2 );747 DO_LOCK( *l __cfaabi_dbg_ctx2 ); 748 748 if(locks) locks[i] = l; 749 749 } … … 803 803 for( int i = 0; i < count; i++ ) { 804 804 805 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );805 // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target ); 806 806 if( &criteria[i] == target ) { 807 807 criteria[i].ready = true; 808 // LIB_DEBUG_PRINT_SAFE( "True\n" );808 // __cfaabi_dbg_print_safe( "True\n" ); 809 809 } 810 810 … … 812 812 } 813 813 814 LIB_DEBUG_PRINT_SAFE( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );814 __cfaabi_dbg_print_safe( "Kernel : Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL ); 815 815 return ready2run ? node->waiting_thread : NULL; 816 816 } … … 819 819 thread_desc * thrd = this_thread; 820 820 if( !this.monitors ) { 821 // LIB_DEBUG_PRINT_SAFE("Branding\n");821 // __cfaabi_dbg_print_safe("Branding\n"); 822 822 assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data ); 823 823 this.monitor_count = thrd->monitors.size; -
src/libcfa/concurrency/preemption.c
r8a0a64d9 r36982fc 148 148 //============================================================================================= 149 149 150 LIB_DEBUG_DO( static thread_local void * last_interrupt = 0; )150 __cfaabi_dbg_debug_do( static thread_local void * last_interrupt = 0; ) 151 151 152 152 extern "C" { … … 159 159 // Enable interrupts by decrementing the counter 160 160 // If counter reaches 0, execute any pending CtxSwitch 161 void enable_interrupts( DEBUG_CTX_PARAM) {161 void enable_interrupts( __cfaabi_dbg_ctx_param ) { 162 162 processor * proc = this_processor; // Cache the processor now since interrupts can start happening after the atomic add 163 163 thread_desc * thrd = this_thread; // Cache the thread now since interrupts can start happening after the atomic add … … 173 173 174 174 // For debugging purposes : keep track of the last person to enable the interrupts 175 LIB_DEBUG_DO( proc->last_enable = caller; )175 __cfaabi_dbg_debug_do( proc->last_enable = caller; ) 176 176 } 177 177 … … 233 233 // Called from kernel_startup 234 234 void kernel_start_preemption() { 235 LIB_DEBUG_PRINT_SAFE("Kernel : Starting preemption\n");235 __cfaabi_dbg_print_safe("Kernel : Starting preemption\n"); 236 236 237 237 // Start with preemption disabled until ready … … 255 255 // Called from kernel_shutdown 256 256 void kernel_stop_preemption() { 257 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n");257 __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n"); 258 258 259 259 // Block all signals since we are already shutting down … … 271 271 // Preemption is now fully stopped 272 272 273 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n");273 __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n"); 274 274 } 275 275 … … 297 297 // Receives SIGUSR1 signal and causes the current thread to yield 298 298 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 299 LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )299 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 300 300 301 301 // Check if it is safe to preempt here … … 346 346 assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int); 347 347 348 // LIB_DEBUG_PRINT_SAFE("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );348 // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int ); 349 349 // Switch on the code (a.k.a. the sender) to 350 350 switch( info.si_code ) … … 354 354 case SI_TIMER: 355 355 case SI_KERNEL: 356 // LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n");357 lock( event_kernel->lock DEBUG_CTX2 );356 // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n"); 357 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 358 358 tick_preemption(); 359 359 unlock( event_kernel->lock ); … … 368 368 369 369 EXIT: 370 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n");370 __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n"); 371 371 return NULL; 372 372 } … … 380 380 381 381 if ( sigaction( sig, &act, NULL ) == -1 ) { 382 LIB_DEBUG_PRINT_BUFFER_DECL(382 __cfaabi_dbg_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(399 __cfaabi_dbg_print_buffer_decl( 400 400 " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n", 401 401 sig, errno, strerror( errno ) … … 409 409 //============================================================================================= 410 410 411 LIB_DEBUG_DO(411 __cfaabi_dbg_debug_do( 412 412 static void __kernel_backtrace( int start ) { 413 413 // skip first N stack frames … … 476 476 477 477 // void sigHandler_segv( __CFA_SIGPARMS__ ) { 478 // LIB_DEBUG_DO(478 // __cfaabi_dbg_debug_do( 479 479 // #ifdef __USE_STREAM__ 480 480 // serr | "*CFA runtime error* program cfa-cpp terminated with" … … 493 493 // void sigHandler_abort( __CFA_SIGPARMS__ ) { 494 494 // // skip first 6 stack frames 495 // LIB_DEBUG_DO( __kernel_backtrace( 6 ); )495 // __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); ) 496 496 497 497 // // reset default signal handler -
src/libcfa/concurrency/thread.c
r8a0a64d9 r36982fc 72 72 thrd_c->last = this_coroutine; 73 73 74 // LIB_DEBUG_PRINT_SAFE("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);74 // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 75 75 76 76 disable_interrupts(); … … 82 82 83 83 ScheduleThread(thrd_h); 84 enable_interrupts( DEBUG_CTX);84 enable_interrupts( __cfaabi_dbg_ctx ); 85 85 } 86 86
Note: See TracChangeset
for help on using the changeset viewer.