Changeset c13e8dc8 for src/libcfa/concurrency/kernel.c
- Timestamp:
- Dec 5, 2017, 2:35:03 PM (8 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f9feab8
- Parents:
- 9c35431 (diff), 65197c2 (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
r9c35431 rc13e8dc8 14 14 // 15 15 16 #include "libhdr.h"17 18 16 //C Includes 19 17 #include <stddef.h> … … 150 148 151 149 this.runner = &runner; 152 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);150 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner); 153 151 runner{ &this }; 154 152 } … … 156 154 void ^?{}(processor & this) { 157 155 if( ! this.do_terminate ) { 158 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);156 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this); 159 157 this.do_terminate = true; 160 158 P( this.terminated ); … … 181 179 processor * this = runner.proc; 182 180 183 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);181 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this); 184 182 185 183 { … … 187 185 preemption_scope scope = { this }; 188 186 189 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);187 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); 190 188 191 189 thread_desc * readyThread = NULL; … … 213 211 } 214 212 215 LIB_DEBUG_PRINT_SAFE("Kernel : core %p stopping\n", this);213 __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this); 216 214 } 217 215 218 216 V( this->terminated ); 219 217 220 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);218 __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this); 221 219 } 222 220 … … 292 290 processorCtx_t proc_cor_storage = { proc, &info }; 293 291 294 LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);292 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 295 293 296 294 //Set global state … … 299 297 300 298 //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);299 __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx); 302 300 303 301 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 310 308 311 309 // 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);310 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner); 313 311 314 312 return NULL; … … 316 314 317 315 void start(processor * this) { 318 LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);316 __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this); 319 317 320 318 pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this ); 321 319 322 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);320 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this); 323 321 } 324 322 … … 334 332 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 335 333 336 lock( this_processor->cltr->ready_queue_lock DEBUG_CTX2 );334 lock( this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 ); 337 335 append( this_processor->cltr->ready_queue, thrd ); 338 336 unlock( this_processor->cltr->ready_queue_lock ); … … 343 341 thread_desc * nextThread(cluster * this) { 344 342 verify( disable_preempt_count > 0 ); 345 lock( this->ready_queue_lock DEBUG_CTX2 );343 lock( this->ready_queue_lock __cfaabi_dbg_ctx2 ); 346 344 thread_desc * head = pop_head( this->ready_queue ); 347 345 unlock( this->ready_queue_lock ); … … 355 353 suspend(); 356 354 verify( disable_preempt_count > 0 ); 357 enable_interrupts( DEBUG_CTX);355 enable_interrupts( __cfaabi_dbg_ctx ); 358 356 } 359 357 … … 367 365 verify( disable_preempt_count > 0 ); 368 366 369 enable_interrupts( DEBUG_CTX);367 enable_interrupts( __cfaabi_dbg_ctx ); 370 368 } 371 369 … … 381 379 verify( disable_preempt_count > 0 ); 382 380 383 enable_interrupts( DEBUG_CTX);381 enable_interrupts( __cfaabi_dbg_ctx ); 384 382 } 385 383 … … 395 393 verify( disable_preempt_count > 0 ); 396 394 397 enable_interrupts( DEBUG_CTX);395 enable_interrupts( __cfaabi_dbg_ctx ); 398 396 } 399 397 … … 408 406 verify( disable_preempt_count > 0 ); 409 407 410 enable_interrupts( DEBUG_CTX);408 enable_interrupts( __cfaabi_dbg_ctx ); 411 409 } 412 410 … … 423 421 verify( disable_preempt_count > 0 ); 424 422 425 enable_interrupts( DEBUG_CTX);423 enable_interrupts( __cfaabi_dbg_ctx ); 426 424 } 427 425 … … 441 439 // Kernel boot procedures 442 440 void kernel_startup(void) { 443 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");441 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 444 442 445 443 // Start by initializing the main thread … … 450 448 (*mainThread){ &info }; 451 449 452 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");450 __cfaabi_dbg_print_safe("Kernel : Main thread ready\n"); 453 451 454 452 // Initialize the main cluster … … 456 454 (*mainCluster){}; 457 455 458 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");456 __cfaabi_dbg_print_safe("Kernel : main cluster ready\n"); 459 457 460 458 // Initialize the main processor and the main processor ctx … … 483 481 484 482 // THE SYSTEM IS NOW COMPLETELY RUNNING 485 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");486 487 enable_interrupts( DEBUG_CTX);483 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 484 485 enable_interrupts( __cfaabi_dbg_ctx ); 488 486 } 489 487 490 488 void kernel_shutdown(void) { 491 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");489 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 492 490 493 491 disable_interrupts(); … … 513 511 ^(mainThread){}; 514 512 515 LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");513 __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n"); 516 514 } 517 515 … … 523 521 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 524 522 // the globalAbort flag is true. 525 lock( kernel_abort_lock DEBUG_CTX2 );523 lock( kernel_abort_lock __cfaabi_dbg_ctx2 ); 526 524 527 525 // first task to abort ? … … 548 546 549 547 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 );548 __cfaabi_dbg_bits_write( abort_text, len ); 551 549 552 550 if ( thrd != this_coroutine ) { 553 551 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine ); 554 __ lib_debug_write( abort_text, len );552 __cfaabi_dbg_bits_write( abort_text, len ); 555 553 } 556 554 else { 557 __ lib_debug_write( ".\n", 2 );555 __cfaabi_dbg_bits_write( ".\n", 2 ); 558 556 } 559 557 } 560 558 561 559 extern "C" { 562 void __ lib_debug_acquire() {563 lock( kernel_debug_lock DEBUG_CTX2 );564 } 565 566 void __ lib_debug_release() {560 void __cfaabi_dbg_bits_acquire() { 561 lock( kernel_debug_lock __cfaabi_dbg_ctx2 ); 562 } 563 564 void __cfaabi_dbg_bits_release() { 567 565 unlock( kernel_debug_lock ); 568 566 } … … 582 580 583 581 void P(semaphore & this) { 584 lock( this.lock DEBUG_CTX2 );582 lock( this.lock __cfaabi_dbg_ctx2 ); 585 583 this.count -= 1; 586 584 if ( this.count < 0 ) { … … 598 596 void V(semaphore & this) { 599 597 thread_desc * thrd = NULL; 600 lock( this.lock DEBUG_CTX2 );598 lock( this.lock __cfaabi_dbg_ctx2 ); 601 599 this.count += 1; 602 600 if ( this.count <= 0 ) {
Note:
See TracChangeset
for help on using the changeset viewer.