Changes in src/libcfa/concurrency/kernel.c [b69ea6b:c40e7c5]
- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rb69ea6b rc40e7c5 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Feb 8 23:52:19201813 // Update Count : 512 // Last Modified On : Tue Feb 6 21:51:26 2018 13 // Update Count : 4 14 14 // 15 15 16 16 //C Includes 17 17 #include <stddef.h> 18 #define ftype `ftype` 18 19 extern "C" { 19 20 #include <stdio.h> … … 23 24 #include <unistd.h> 24 25 } 26 #undef ftype 25 27 26 28 //CFA Includes … … 56 58 thread_local processor * volatile this_processor; 57 59 58 // volatile thread_local bool preemption_in_progress = 0; 59 // volatile thread_local bool preemption_enabled = false; 60 // volatile thread_local unsigned short disable_preempt_count = 1; 61 62 volatile thread_local __cfa_kernel_preemption_data_t preemption = { false, false, 1 }; 60 volatile thread_local bool preemption_in_progress = 0; 61 volatile thread_local bool preemption_enabled = false; 62 volatile thread_local unsigned short disable_preempt_count = 1; 63 63 64 64 //----------------------------------------------------------------------------- … … 209 209 if(readyThread) 210 210 { 211 verify( !preemption .enabled );211 verify( !preemption_enabled ); 212 212 213 213 runThread(this, readyThread); 214 214 215 verify( !preemption .enabled );215 verify( !preemption_enabled ); 216 216 217 217 //Some actions need to be taken from the kernel … … 262 262 void finishRunning(processor * this) with( this->finish ) { 263 263 if( action_code == Release ) { 264 verify( !preemption .enabled );264 verify( !preemption_enabled ); 265 265 unlock( *lock ); 266 266 } … … 269 269 } 270 270 else if( action_code == Release_Schedule ) { 271 verify( !preemption .enabled );271 verify( !preemption_enabled ); 272 272 unlock( *lock ); 273 273 ScheduleThread( thrd ); 274 274 } 275 275 else if( action_code == Release_Multi ) { 276 verify( !preemption .enabled );276 verify( !preemption_enabled ); 277 277 for(int i = 0; i < lock_count; i++) { 278 278 unlock( *locks[i] ); … … 306 306 this_coroutine = NULL; 307 307 this_thread = NULL; 308 preemption .enabled = false;309 preemption.disable_count = 1;308 preemption_enabled = false; 309 disable_preempt_count = 1; 310 310 // SKULLDUGGERY: We want to create a context for the processor coroutine 311 311 // which is needed for the 2-step context switch. However, there is no reason … … 347 347 } 348 348 349 void kernel_first_resume(processor * this) {350 coroutine_desc * src = this_coroutine;351 coroutine_desc * dst = get_coroutine(*this->runner);352 353 verify( !preemption.enabled );354 355 create_stack(&dst->stack, dst->stack.size);356 CtxStart(this->runner, CtxInvokeCoroutine);357 358 verify( !preemption.enabled );359 360 dst->last = src;361 dst->starter = dst->starter ? dst->starter : src;362 363 // set state of current coroutine to inactive364 src->state = src->state == Halted ? Halted : Inactive;365 366 // set new coroutine that task is executing367 this_coroutine = dst;368 369 // SKULLDUGGERY normally interrupts are enable before leaving a coroutine ctxswitch.370 // Therefore, when first creating a coroutine, interrupts are enable before calling the main.371 // This is consistent with thread creation. However, when creating the main processor coroutine,372 // we wan't interrupts to be disabled. Therefore, we double-disable interrupts here so they will373 // stay disabled.374 disable_interrupts();375 376 // context switch to specified coroutine377 assert( src->stack.context );378 CtxSwitch( src->stack.context, dst->stack.context );379 // when CtxSwitch returns we are back in the src coroutine380 381 // set state of new coroutine to active382 src->state = Active;383 384 verify( !preemption.enabled );385 }386 387 349 //----------------------------------------------------------------------------- 388 350 // Scheduler routines … … 392 354 verify( thrd->self_cor.state != Halted ); 393 355 394 verify( !preemption .enabled );356 verify( !preemption_enabled ); 395 357 396 358 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 402 364 } 403 365 404 verify( !preemption .enabled );366 verify( !preemption_enabled ); 405 367 } 406 368 407 369 thread_desc * nextThread(cluster * this) with( *this ) { 408 verify( !preemption .enabled );370 verify( !preemption_enabled ); 409 371 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 410 372 thread_desc * head = pop_head( ready_queue ); 411 373 unlock( ready_queue_lock ); 412 verify( !preemption .enabled );374 verify( !preemption_enabled ); 413 375 return head; 414 376 } … … 416 378 void BlockInternal() { 417 379 disable_interrupts(); 418 verify( !preemption .enabled );419 returnToKernel(); 420 verify( !preemption .enabled );380 verify( !preemption_enabled ); 381 returnToKernel(); 382 verify( !preemption_enabled ); 421 383 enable_interrupts( __cfaabi_dbg_ctx ); 422 384 } … … 427 389 this_processor->finish.lock = lock; 428 390 429 verify( !preemption .enabled );430 returnToKernel(); 431 verify( !preemption .enabled );391 verify( !preemption_enabled ); 392 returnToKernel(); 393 verify( !preemption_enabled ); 432 394 433 395 enable_interrupts( __cfaabi_dbg_ctx ); … … 439 401 this_processor->finish.thrd = thrd; 440 402 441 verify( !preemption .enabled );442 returnToKernel(); 443 verify( !preemption .enabled );403 verify( !preemption_enabled ); 404 returnToKernel(); 405 verify( !preemption_enabled ); 444 406 445 407 enable_interrupts( __cfaabi_dbg_ctx ); … … 453 415 this_processor->finish.thrd = thrd; 454 416 455 verify( !preemption .enabled );456 returnToKernel(); 457 verify( !preemption .enabled );417 verify( !preemption_enabled ); 418 returnToKernel(); 419 verify( !preemption_enabled ); 458 420 459 421 enable_interrupts( __cfaabi_dbg_ctx ); … … 466 428 this_processor->finish.lock_count = count; 467 429 468 verify( !preemption .enabled );469 returnToKernel(); 470 verify( !preemption .enabled );430 verify( !preemption_enabled ); 431 returnToKernel(); 432 verify( !preemption_enabled ); 471 433 472 434 enable_interrupts( __cfaabi_dbg_ctx ); … … 481 443 this_processor->finish.thrd_count = thrd_count; 482 444 483 verify( !preemption .enabled );484 returnToKernel(); 485 verify( !preemption .enabled );445 verify( !preemption_enabled ); 446 returnToKernel(); 447 verify( !preemption_enabled ); 486 448 487 449 enable_interrupts( __cfaabi_dbg_ctx ); … … 489 451 490 452 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 491 verify( !preemption .enabled );453 verify( !preemption_enabled ); 492 454 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 493 455 this_processor->finish.lock = lock; … … 503 465 // Kernel boot procedures 504 466 void kernel_startup(void) { 505 verify( !preemption.enabled );506 467 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 507 468 … … 541 502 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 542 503 // mainThread is on the ready queue when this call is made. 543 kernel_first_resume( this_processor );504 resume( *mainProcessor->runner ); 544 505 545 506 … … 548 509 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 549 510 550 verify( !preemption.enabled );551 511 enable_interrupts( __cfaabi_dbg_ctx ); 552 verify( preemption.enabled );553 512 } 554 513 … … 556 515 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 557 516 558 verify( preemption.enabled );559 517 disable_interrupts(); 560 verify( !preemption.enabled );561 518 562 519 // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
Note:
See TracChangeset
for help on using the changeset viewer.