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