- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r82ff5845 rc81ebf9 154 154 (&this->terminated){}; 155 155 this->is_terminated = false; 156 this->preemption_alarm = NULL; 157 this->preemption = default_preemption(); 158 this->disable_preempt_count = 1; 156 this->disable_preempt_count = 0; 159 157 this->pending_preemption = false; 160 this->kernel_thread = pthread_self();161 158 162 159 this->runner = runner; 163 LIB_DEBUG_PRINT_SAFE("Kernel : constructing systemprocessor context %p\n", runner);160 LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner); 164 161 runner{ this }; 165 162 } … … 243 240 //Update global state 244 241 this->current_thread = dst; 245 246 LIB_DEBUG_PRINT_SAFE("Kernel : running %p\n", dst);247 242 248 243 // Context Switch to the thread … … 327 322 void start(processor * this) { 328 323 LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this); 329 330 // SIGALRM must only be caught by the system processor 331 sigset_t old_mask; 332 bool is_system_proc = this_processor == &systemProcessor->proc; 333 if ( is_system_proc ) { 334 // Child kernel-thread inherits the signal mask from the parent kernel-thread. So one special case for the 335 // system processor creating the user processor => toggle the blocking SIGALRM on system processor, create user 336 // processor, and toggle back (below) previous signal mask of the system processor. 337 338 sigset_t new_mask; 339 sigemptyset( &new_mask ); 340 sigemptyset( &old_mask ); 341 sigaddset( &new_mask, SIGALRM ); 342 343 if ( sigprocmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) { 344 abortf( "internal error, sigprocmask" ); 345 } 346 347 assert( ! sigismember( &old_mask, SIGALRM ) ); 348 } 349 324 350 325 pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this ); 351 352 // Toggle back previous signal mask of system processor.353 if ( is_system_proc ) {354 if ( sigprocmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) {355 abortf( "internal error, sigprocmask" );356 } // if357 } // if358 326 359 327 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this); … … 379 347 } 380 348 381 void BlockInternal() { 382 disable_interrupts(); 349 void ScheduleInternal() { 383 350 suspend(); 384 enable_interrupts(); 385 } 386 387 void BlockInternal( spinlock * lock ) { 388 disable_interrupts(); 351 } 352 353 void ScheduleInternal( spinlock * lock ) { 389 354 this_processor->finish.action_code = Release; 390 355 this_processor->finish.lock = lock; 391 356 suspend(); 392 enable_interrupts(); 393 } 394 395 void BlockInternal( thread_desc * thrd ) { 396 disable_interrupts(); 357 } 358 359 void ScheduleInternal( thread_desc * thrd ) { 397 360 this_processor->finish.action_code = Schedule; 398 361 this_processor->finish.thrd = thrd; 399 362 suspend(); 400 enable_interrupts(); 401 } 402 403 void BlockInternal( spinlock * lock, thread_desc * thrd ) { 404 disable_interrupts(); 363 } 364 365 void ScheduleInternal( spinlock * lock, thread_desc * thrd ) { 405 366 this_processor->finish.action_code = Release_Schedule; 406 367 this_processor->finish.lock = lock; 407 368 this_processor->finish.thrd = thrd; 408 369 suspend(); 409 enable_interrupts(); 410 } 411 412 void BlockInternal(spinlock ** locks, unsigned short count) { 413 disable_interrupts(); 370 } 371 372 void ScheduleInternal(spinlock ** locks, unsigned short count) { 414 373 this_processor->finish.action_code = Release_Multi; 415 374 this_processor->finish.locks = locks; 416 375 this_processor->finish.lock_count = count; 417 376 suspend(); 418 enable_interrupts(); 419 } 420 421 void BlockInternal(spinlock ** locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) { 422 disable_interrupts(); 377 } 378 379 void ScheduleInternal(spinlock ** locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) { 423 380 this_processor->finish.action_code = Release_Multi_Schedule; 424 381 this_processor->finish.locks = locks; … … 427 384 this_processor->finish.thrd_count = thrd_count; 428 385 suspend(); 429 enable_interrupts();430 386 } 431 387 … … 447 403 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); 448 404 405 // Enable preemption 406 kernel_start_preemption(); 407 449 408 // Initialize the system cluster 450 409 systemCluster = (cluster *)&systemCluster_storage; … … 467 426 this_processor->current_coroutine = &mainThread->cor; 468 427 469 // Enable preemption470 kernel_start_preemption();471 472 428 // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX 473 429 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that … … 479 435 // THE SYSTEM IS NOW COMPLETELY RUNNING 480 436 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 481 482 enable_interrupts();483 437 } 484 438 … … 493 447 494 448 // THE SYSTEM IS NOW COMPLETELY STOPPED 495 496 // Disable preemption497 kernel_stop_preemption();498 449 499 450 // Destroy the system processor and its context in reverse order of construction … … 599 550 if( !this->cond ) { 600 551 append( &this->blocked, this_thread() ); 601 BlockInternal( &this->lock );552 ScheduleInternal( &this->lock ); 602 553 lock( &this->lock ); 603 554 }
Note:
See TracChangeset
for help on using the changeset viewer.