- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/preemption.c
rb69ea6b rd8548e2 23 23 } 24 24 25 #include "bits/cfatime.h" 25 26 #include "bits/signal.h" 26 27 27 //TODO move to defaults 28 #define __CFA_DEFAULT_PREEMPTION__ 10 00029 30 //TODO move to defaults 31 __ attribute__((weak)) unsigned int default_preemption() {28 #if !defined(__CFA_DEFAULT_PREEMPTION__) 29 #define __CFA_DEFAULT_PREEMPTION__ 10`cfa_ms 30 #endif 31 32 __cfa_time_t default_preemption() __attribute__((weak)) { 32 33 return __CFA_DEFAULT_PREEMPTION__; 33 34 } … … 149 150 // Disable interrupts by incrementing the counter 150 151 void disable_interrupts() { 151 preemption .enabled = false;152 __attribute__((unused)) unsigned short new_val = preemption .disable_count + 1;153 preemption .disable_count = new_val;152 preemption_state.enabled = false; 153 __attribute__((unused)) unsigned short new_val = preemption_state.disable_count + 1; 154 preemption_state.disable_count = new_val; 154 155 verify( new_val < 65_000u ); // If this triggers someone is disabling interrupts without enabling them 155 156 } … … 161 162 thread_desc * thrd = this_thread; // Cache the thread now since interrupts can start happening after the atomic add 162 163 163 unsigned short prev = preemption .disable_count;164 preemption .disable_count -= 1;164 unsigned short prev = preemption_state.disable_count; 165 preemption_state.disable_count -= 1; 165 166 verify( prev != 0u ); // If this triggers someone is enabled already enabled interruptsverify( prev != 0u ); 166 167 167 168 // Check if we need to prempt the thread because an interrupt was missed 168 169 if( prev == 1 ) { 169 preemption .enabled = true;170 preemption_state.enabled = true; 170 171 if( proc->pending_preemption ) { 171 172 proc->pending_preemption = false; … … 181 182 // Don't execute any pending CtxSwitch even if counter reaches 0 182 183 void enable_interrupts_noPoll() { 183 unsigned short prev = preemption .disable_count;184 preemption .disable_count -= 1;184 unsigned short prev = preemption_state.disable_count; 185 preemption_state.disable_count -= 1; 185 186 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 186 187 if( prev == 1 ) { 187 preemption .enabled = true;188 preemption_state.enabled = true; 188 189 } 189 190 } … … 235 236 // If false : preemption is unsafe and marked as pending 236 237 static inline bool preemption_ready() { 237 bool ready = preemption .enabled && !preemption.in_progress; // Check if preemption is safe238 bool ready = preemption_state.enabled && !preemption_state.in_progress; // Check if preemption is safe 238 239 this_processor->pending_preemption = !ready; // Adjust the pending flag accordingly 239 240 return ready; … … 250 251 251 252 // Start with preemption disabled until ready 252 preemption .enabled = false;253 preemption .disable_count = 1;253 preemption_state.enabled = false; 254 preemption_state.disable_count = 1; 254 255 255 256 // Initialize the event kernel … … 294 295 this.proc->preemption_alarm = &this.alarm; 295 296 296 update_preemption( this.proc, from_us(this.proc->cltr->preemption));297 update_preemption( this.proc, this.proc->cltr->preemption_rate ); 297 298 } 298 299 … … 330 331 __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread); 331 332 332 preemption .in_progress = true; // Sync flag : prevent recursive calls to the signal handler333 preemption_state.in_progress = true; // Sync flag : prevent recursive calls to the signal handler 333 334 signal_unblock( SIGUSR1 ); // We are about to CtxSwitch out of the signal handler, let other handlers in 334 preemption .in_progress = false; // Clear the in progress flag335 preemption_state.in_progress = false; // Clear the in progress flag 335 336 336 337 // Preemption can occur here
Note: See TracChangeset
for help on using the changeset viewer.