Changeset b10affd for src/libcfa/concurrency/preemption.c
- Timestamp:
- Mar 30, 2018, 7:21:28 PM (6 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, with_gc
- Children:
- 273cde6
- Parents:
- fae90d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/preemption.c
rfae90d5 rb10affd 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 27 11:28:51201813 // Update Count : 2412 // Last Modified On : Fri Mar 30 17:27:43 2018 13 // Update Count : 31 14 14 // 15 15 … … 150 150 // Disable interrupts by incrementing the counter 151 151 void disable_interrupts() { 152 preemption_state.enabled = false;153 __attribute__((unused)) unsigned short new_val = preemption_state.disable_count + 1;154 preemption_state.disable_count = new_val;152 TL_GET( preemption_state ).enabled = false; 153 __attribute__((unused)) unsigned short new_val = TL_GET( preemption_state ).disable_count + 1; 154 TL_GET( preemption_state ).disable_count = new_val; 155 155 verify( new_val < 65_000u ); // If this triggers someone is disabling interrupts without enabling them 156 156 } … … 159 159 // If counter reaches 0, execute any pending CtxSwitch 160 160 void enable_interrupts( __cfaabi_dbg_ctx_param ) { 161 processor * proc = this_processor;// Cache the processor now since interrupts can start happening after the atomic add162 thread_desc * thrd = this_thread;// Cache the thread now since interrupts can start happening after the atomic add163 164 unsigned short prev = preemption_state.disable_count;165 preemption_state.disable_count -= 1;161 processor * proc = TL_GET( this_processor ); // Cache the processor now since interrupts can start happening after the atomic add 162 thread_desc * thrd = TL_GET( this_thread ); // Cache the thread now since interrupts can start happening after the atomic add 163 164 unsigned short prev = TL_GET( preemption_state ).disable_count; 165 TL_GET( preemption_state ).disable_count -= 1; 166 166 verify( prev != 0u ); // If this triggers someone is enabled already enabled interruptsverify( prev != 0u ); 167 167 168 168 // Check if we need to prempt the thread because an interrupt was missed 169 169 if( prev == 1 ) { 170 preemption_state.enabled = true;170 TL_GET( preemption_state ).enabled = true; 171 171 if( proc->pending_preemption ) { 172 172 proc->pending_preemption = false; … … 182 182 // Don't execute any pending CtxSwitch even if counter reaches 0 183 183 void enable_interrupts_noPoll() { 184 unsigned short prev = preemption_state.disable_count;185 preemption_state.disable_count -= 1;184 unsigned short prev = TL_GET( preemption_state ).disable_count; 185 TL_GET( preemption_state ).disable_count -= 1; 186 186 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 187 187 if( prev == 1 ) { 188 preemption_state.enabled = true;188 TL_GET( preemption_state ).enabled = true; 189 189 } 190 190 } … … 236 236 // If false : preemption is unsafe and marked as pending 237 237 static inline bool preemption_ready() { 238 bool ready = preemption_state.enabled && !preemption_state.in_progress; // Check if preemption is safe239 this_processor->pending_preemption = !ready;// Adjust the pending flag accordingly238 bool ready = TL_GET( preemption_state ).enabled && !TL_GET( preemption_state ).in_progress; // Check if preemption is safe 239 TL_GET( this_processor )->pending_preemption = !ready; // Adjust the pending flag accordingly 240 240 return ready; 241 241 } … … 251 251 252 252 // Start with preemption disabled until ready 253 preemption_state.enabled = false;254 preemption_state.disable_count = 1;253 TL_GET( preemption_state ).enabled = false; 254 TL_GET( preemption_state ).disable_count = 1; 255 255 256 256 // Initialize the event kernel … … 317 317 // before the kernel thread has even started running. When that happens an iterrupt 318 318 // we a null 'this_processor' will be caught, just ignore it. 319 if(! this_processor) return;319 if(!TL_GET( this_processor )) return; 320 320 321 321 choose(sfp->si_value.sival_int) { 322 322 case PREEMPT_NORMAL : ;// Normal case, nothing to do here 323 case PREEMPT_TERMINATE: verify( this_processor->do_terminate);323 case PREEMPT_TERMINATE: verify(TL_GET( this_processor )->do_terminate); 324 324 default: 325 325 abort( "internal error, signal value is %d", sfp->si_value.sival_int ); … … 331 331 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread); 332 332 333 preemption_state.in_progress = true;// Sync flag : prevent recursive calls to the signal handler333 TL_GET( preemption_state ).in_progress = true; // Sync flag : prevent recursive calls to the signal handler 334 334 signal_unblock( SIGUSR1 ); // We are about to CtxSwitch out of the signal handler, let other handlers in 335 preemption_state.in_progress = false;// Clear the in progress flag335 TL_GET( preemption_state ).in_progress = false; // Clear the in progress flag 336 336 337 337 // Preemption can occur here 338 338 339 BlockInternal( (thread_desc*) this_thread );// Do the actual CtxSwitch339 BlockInternal( (thread_desc*)TL_GET( this_thread ) ); // Do the actual CtxSwitch 340 340 } 341 341
Note: See TracChangeset
for help on using the changeset viewer.