- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r65deb18 rd0a045c7 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:33:18201713 // Update Count : 212 // Last Modified On : Fri Dec 8 16:23:33 2017 13 // Update Count : 3 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 … … 57 59 58 60 volatile thread_local bool preemption_in_progress = 0; 61 volatile thread_local bool preemption_enabled = false; 59 62 volatile thread_local unsigned short disable_preempt_count = 1; 60 63 … … 194 197 if(readyThread) 195 198 { 196 verify( disable_preempt_count > 0);199 verify( !preemption_enabled ); 197 200 198 201 runThread(this, readyThread); 199 202 200 verify( disable_preempt_count > 0);203 verify( !preemption_enabled ); 201 204 202 205 //Some actions need to be taken from the kernel … … 240 243 void finishRunning(processor * this) with( this->finish ) { 241 244 if( action_code == Release ) { 245 verify( !preemption_enabled ); 242 246 unlock( *lock ); 243 247 } … … 246 250 } 247 251 else if( action_code == Release_Schedule ) { 252 verify( !preemption_enabled ); 248 253 unlock( *lock ); 249 254 ScheduleThread( thrd ); 250 255 } 251 256 else if( action_code == Release_Multi ) { 257 verify( !preemption_enabled ); 252 258 for(int i = 0; i < lock_count; i++) { 253 259 unlock( *locks[i] ); … … 281 287 this_coroutine = NULL; 282 288 this_thread = NULL; 289 preemption_enabled = false; 283 290 disable_preempt_count = 1; 284 291 // SKULLDUGGERY: We want to create a context for the processor coroutine … … 328 335 verify( thrd->self_cor.state != Halted ); 329 336 330 verify( disable_preempt_count > 0);337 verify( !preemption_enabled ); 331 338 332 339 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 338 345 } 339 346 340 verify( disable_preempt_count > 0);347 verify( !preemption_enabled ); 341 348 } 342 349 343 350 thread_desc * nextThread(cluster * this) with( *this ) { 344 verify( disable_preempt_count > 0);351 verify( !preemption_enabled ); 345 352 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 346 353 thread_desc * head = pop_head( ready_queue ); 347 354 unlock( ready_queue_lock ); 348 verify( disable_preempt_count > 0);355 verify( !preemption_enabled ); 349 356 return head; 350 357 } … … 352 359 void BlockInternal() { 353 360 disable_interrupts(); 354 verify( disable_preempt_count > 0);355 suspend(); 356 verify( disable_preempt_count > 0);361 verify( !preemption_enabled ); 362 suspend(); 363 verify( !preemption_enabled ); 357 364 enable_interrupts( __cfaabi_dbg_ctx ); 358 365 } … … 363 370 this_processor->finish.lock = lock; 364 371 365 verify( disable_preempt_count > 0);366 suspend(); 367 verify( disable_preempt_count > 0);372 verify( !preemption_enabled ); 373 suspend(); 374 verify( !preemption_enabled ); 368 375 369 376 enable_interrupts( __cfaabi_dbg_ctx ); … … 375 382 this_processor->finish.thrd = thrd; 376 383 377 verify( disable_preempt_count > 0);378 suspend(); 379 verify( disable_preempt_count > 0);384 verify( !preemption_enabled ); 385 suspend(); 386 verify( !preemption_enabled ); 380 387 381 388 enable_interrupts( __cfaabi_dbg_ctx ); … … 389 396 this_processor->finish.thrd = thrd; 390 397 391 verify( disable_preempt_count > 0);392 suspend(); 393 verify( disable_preempt_count > 0);398 verify( !preemption_enabled ); 399 suspend(); 400 verify( !preemption_enabled ); 394 401 395 402 enable_interrupts( __cfaabi_dbg_ctx ); … … 402 409 this_processor->finish.lock_count = count; 403 410 404 verify( disable_preempt_count > 0);405 suspend(); 406 verify( disable_preempt_count > 0);411 verify( !preemption_enabled ); 412 suspend(); 413 verify( !preemption_enabled ); 407 414 408 415 enable_interrupts( __cfaabi_dbg_ctx ); … … 417 424 this_processor->finish.thrd_count = thrd_count; 418 425 419 verify( disable_preempt_count > 0);420 suspend(); 421 verify( disable_preempt_count > 0);426 verify( !preemption_enabled ); 427 suspend(); 428 verify( !preemption_enabled ); 422 429 423 430 enable_interrupts( __cfaabi_dbg_ctx ); … … 425 432 426 433 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 427 verify( disable_preempt_count > 0);434 verify( !preemption_enabled ); 428 435 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 429 436 this_processor->finish.lock = lock; … … 513 520 __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n"); 514 521 } 522 523 //============================================================================================= 524 // Unexpected Terminating logic 525 //============================================================================================= 526 515 527 516 528 static __spinlock_t kernel_abort_lock; … … 609 621 } 610 622 623 //----------------------------------------------------------------------------- 624 // Debug 625 __cfaabi_dbg_debug_do( 626 struct { 627 thread_desc * tail; 628 } __cfaabi_dbg_thread_list = { NULL }; 629 630 void __cfaabi_dbg_thread_register( thread_desc * thrd ) { 631 if( !__cfaabi_dbg_thread_list.tail ) { 632 __cfaabi_dbg_thread_list.tail = thrd; 633 return; 634 } 635 __cfaabi_dbg_thread_list.tail->dbg_next = thrd; 636 thrd->dbg_prev = __cfaabi_dbg_thread_list.tail; 637 __cfaabi_dbg_thread_list.tail = thrd; 638 } 639 640 void __cfaabi_dbg_thread_unregister( thread_desc * thrd ) { 641 thread_desc * prev = thrd->dbg_prev; 642 thread_desc * next = thrd->dbg_next; 643 644 if( next ) { next->dbg_prev = prev; } 645 else { 646 assert( __cfaabi_dbg_thread_list.tail == thrd ); 647 __cfaabi_dbg_thread_list.tail = prev; 648 } 649 650 if( prev ) { prev->dbg_next = next; } 651 652 thrd->dbg_prev = NULL; 653 thrd->dbg_next = NULL; 654 } 655 ) 611 656 // Local Variables: // 612 657 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.