Changeset d0a045c7
- Timestamp:
- Feb 1, 2018, 5:37:37 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 85521c7
- Parents:
- e76bd39
- Location:
- src/libcfa/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
re76bd39 rd0a045c7 59 59 60 60 volatile thread_local bool preemption_in_progress = 0; 61 volatile thread_local bool preemption_enabled = false; 61 62 volatile thread_local unsigned short disable_preempt_count = 1; 62 63 … … 196 197 if(readyThread) 197 198 { 198 verify( disable_preempt_count > 0);199 verify( !preemption_enabled ); 199 200 200 201 runThread(this, readyThread); 201 202 202 verify( disable_preempt_count > 0);203 verify( !preemption_enabled ); 203 204 204 205 //Some actions need to be taken from the kernel … … 242 243 void finishRunning(processor * this) with( this->finish ) { 243 244 if( action_code == Release ) { 244 verify( disable_preempt_count > 1);245 verify( !preemption_enabled ); 245 246 unlock( *lock ); 246 247 } … … 249 250 } 250 251 else if( action_code == Release_Schedule ) { 251 verify( disable_preempt_count > 1);252 verify( !preemption_enabled ); 252 253 unlock( *lock ); 253 254 ScheduleThread( thrd ); 254 255 } 255 256 else if( action_code == Release_Multi ) { 256 verify( disable_preempt_count > lock_count);257 verify( !preemption_enabled ); 257 258 for(int i = 0; i < lock_count; i++) { 258 259 unlock( *locks[i] ); … … 286 287 this_coroutine = NULL; 287 288 this_thread = NULL; 289 preemption_enabled = false; 288 290 disable_preempt_count = 1; 289 291 // SKULLDUGGERY: We want to create a context for the processor coroutine … … 333 335 verify( thrd->self_cor.state != Halted ); 334 336 335 verify( disable_preempt_count > 0);337 verify( !preemption_enabled ); 336 338 337 339 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 343 345 } 344 346 345 verify( disable_preempt_count > 0);347 verify( !preemption_enabled ); 346 348 } 347 349 348 350 thread_desc * nextThread(cluster * this) with( *this ) { 349 verify( disable_preempt_count > 0);351 verify( !preemption_enabled ); 350 352 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 351 353 thread_desc * head = pop_head( ready_queue ); 352 354 unlock( ready_queue_lock ); 353 verify( disable_preempt_count > 0);355 verify( !preemption_enabled ); 354 356 return head; 355 357 } … … 357 359 void BlockInternal() { 358 360 disable_interrupts(); 359 verify( disable_preempt_count > 0);360 suspend(); 361 verify( disable_preempt_count > 0);361 verify( !preemption_enabled ); 362 suspend(); 363 verify( !preemption_enabled ); 362 364 enable_interrupts( __cfaabi_dbg_ctx ); 363 365 } … … 368 370 this_processor->finish.lock = lock; 369 371 370 verify( disable_preempt_count > 1);371 suspend(); 372 verify( disable_preempt_count > 0);372 verify( !preemption_enabled ); 373 suspend(); 374 verify( !preemption_enabled ); 373 375 374 376 enable_interrupts( __cfaabi_dbg_ctx ); … … 380 382 this_processor->finish.thrd = thrd; 381 383 382 verify( disable_preempt_count > 0);383 suspend(); 384 verify( disable_preempt_count > 0);384 verify( !preemption_enabled ); 385 suspend(); 386 verify( !preemption_enabled ); 385 387 386 388 enable_interrupts( __cfaabi_dbg_ctx ); … … 394 396 this_processor->finish.thrd = thrd; 395 397 396 verify( disable_preempt_count > 1);397 suspend(); 398 verify( disable_preempt_count > 0);398 verify( !preemption_enabled ); 399 suspend(); 400 verify( !preemption_enabled ); 399 401 400 402 enable_interrupts( __cfaabi_dbg_ctx ); … … 407 409 this_processor->finish.lock_count = count; 408 410 409 verify( disable_preempt_count > 0);410 suspend(); 411 verify( disable_preempt_count > 0);411 verify( !preemption_enabled ); 412 suspend(); 413 verify( !preemption_enabled ); 412 414 413 415 enable_interrupts( __cfaabi_dbg_ctx ); … … 422 424 this_processor->finish.thrd_count = thrd_count; 423 425 424 verify( disable_preempt_count > 0);425 suspend(); 426 verify( disable_preempt_count > 0);426 verify( !preemption_enabled ); 427 suspend(); 428 verify( !preemption_enabled ); 427 429 428 430 enable_interrupts( __cfaabi_dbg_ctx ); … … 430 432 431 433 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 432 verify( disable_preempt_count > 0);434 verify( !preemption_enabled ); 433 435 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 434 436 this_processor->finish.lock = lock; -
src/libcfa/concurrency/kernel_private.h
re76bd39 rd0a045c7 74 74 75 75 extern volatile thread_local bool preemption_in_progress; 76 extern volatile thread_local bool preemption_enabled; 76 77 extern volatile thread_local unsigned short disable_preempt_count; 77 78 -
src/libcfa/concurrency/monitor.c
re76bd39 rd0a045c7 87 87 thread_desc * thrd = this_thread; 88 88 89 verify( disable_preempt_count > 0 );90 91 89 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 92 90 … … 117 115 // Some one else has the monitor, wait in line for it 118 116 append( this->entry_queue, thrd ); 119 120 verify( disable_preempt_count > 0 );121 117 122 118 BlockInternal( &this->lock ); … … 396 392 append( this.blocked, &waiter ); 397 393 398 verify( disable_preempt_count == 0 );399 400 394 // Lock all monitors (aggregates the locks as well) 401 395 lock_all( monitors, locks, count ); 402 403 // verifyf( disable_preempt_count == count, "Got %d, expected %d\n", disable_preempt_count, count );404 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); }405 396 406 397 // Find the next thread(s) to run … … 477 468 monitor_ctx( this.monitors, this.monitor_count ); 478 469 479 verify( disable_preempt_count == 0 );480 481 470 // Lock all monitors (aggregates the locks them as well) 482 471 lock_all( monitors, locks, count ); 483 484 // verify( disable_preempt_count == count );485 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); }486 472 487 473 -
src/libcfa/concurrency/preemption.c
re76bd39 rd0a045c7 142 142 // Disable interrupts by incrementing the counter 143 143 void disable_interrupts() { 144 __attribute__((unused)) unsigned short new_val = __atomic_add_fetch_2( &disable_preempt_count, 1, __ATOMIC_SEQ_CST ); 144 preemption_enabled = false; 145 __attribute__((unused)) unsigned short new_val = disable_preempt_count + 1; 146 disable_preempt_count = new_val; 145 147 verify( new_val < 65_000u ); // If this triggers someone is disabling interrupts without enabling them 146 148 } … … 152 154 thread_desc * thrd = this_thread; // Cache the thread now since interrupts can start happening after the atomic add 153 155 154 unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 156 unsigned short prev = disable_preempt_count; 157 disable_preempt_count -= 1; 155 158 verify( prev != 0u ); // If this triggers someone is enabled already enabled interruptsverify( prev != 0u ); 156 159 157 160 // Check if we need to prempt the thread because an interrupt was missed 158 if( prev == 1 && proc->pending_preemption ) { 159 proc->pending_preemption = false; 160 BlockInternal( thrd ); 161 if( prev == 1 ) { 162 preemption_enabled = true; 163 if( proc->pending_preemption ) { 164 proc->pending_preemption = false; 165 BlockInternal( thrd ); 166 } 161 167 } 162 168 … … 168 174 // Don't execute any pending CtxSwitch even if counter reaches 0 169 175 void enable_interrupts_noPoll() { 170 __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 176 unsigned short prev = disable_preempt_count; 177 disable_preempt_count -= 1; 171 178 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 179 if( prev == 1 ) { 180 preemption_enabled = true; 181 } 172 182 } 173 183 } … … 210 220 // If false : preemption is unsafe and marked as pending 211 221 static inline bool preemption_ready() { 212 bool ready = disable_preempt_count == 0&& !preemption_in_progress; // Check if preemption is safe222 bool ready = preemption_enabled && !preemption_in_progress; // Check if preemption is safe 213 223 this_processor->pending_preemption = !ready; // Adjust the pending flag accordingly 214 224 return ready; … … 225 235 226 236 // Start with preemption disabled until ready 237 preemption_enabled = false; 227 238 disable_preempt_count = 1; 228 239
Note: See TracChangeset
for help on using the changeset viewer.