Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/preemption.c

    rd8548e2 rb69ea6b  
    2323}
    2424
    25 #include "bits/cfatime.h"
    2625#include "bits/signal.h"
    2726
    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)) {
     27//TODO move to defaults
     28#define __CFA_DEFAULT_PREEMPTION__ 10000
     29
     30//TODO move to defaults
     31__attribute__((weak)) unsigned int default_preemption() {
    3332        return __CFA_DEFAULT_PREEMPTION__;
    3433}
     
    150149        // Disable interrupts by incrementing the counter
    151150        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;
     151                preemption.enabled = false;
     152                __attribute__((unused)) unsigned short new_val = preemption.disable_count + 1;
     153                preemption.disable_count = new_val;
    155154                verify( new_val < 65_000u );              // If this triggers someone is disabling interrupts without enabling them
    156155        }
     
    162161                thread_desc * thrd = this_thread;         // Cache the thread now since interrupts can start happening after the atomic add
    163162
    164                 unsigned short prev = preemption_state.disable_count;
    165                 preemption_state.disable_count -= 1;
     163                unsigned short prev = preemption.disable_count;
     164                preemption.disable_count -= 1;
    166165                verify( prev != 0u );                     // If this triggers someone is enabled already enabled interruptsverify( prev != 0u );
    167166
    168167                // Check if we need to prempt the thread because an interrupt was missed
    169168                if( prev == 1 ) {
    170                         preemption_state.enabled = true;
     169                        preemption.enabled = true;
    171170                        if( proc->pending_preemption ) {
    172171                                proc->pending_preemption = false;
     
    182181        // Don't execute any pending CtxSwitch even if counter reaches 0
    183182        void enable_interrupts_noPoll() {
    184                 unsigned short prev = preemption_state.disable_count;
    185                 preemption_state.disable_count -= 1;
     183                unsigned short prev = preemption.disable_count;
     184                preemption.disable_count -= 1;
    186185                verifyf( prev != 0u, "Incremented from %u\n", prev );                     // If this triggers someone is enabled already enabled interrupts
    187186                if( prev == 1 ) {
    188                         preemption_state.enabled = true;
     187                        preemption.enabled = true;
    189188                }
    190189        }
     
    236235// If false : preemption is unsafe and marked as pending
    237236static inline bool preemption_ready() {
    238         bool ready = preemption_state.enabled && !preemption_state.in_progress; // Check if preemption is safe
     237        bool ready = preemption.enabled && !preemption.in_progress; // Check if preemption is safe
    239238        this_processor->pending_preemption = !ready;                        // Adjust the pending flag accordingly
    240239        return ready;
     
    251250
    252251        // Start with preemption disabled until ready
    253         preemption_state.enabled = false;
    254         preemption_state.disable_count = 1;
     252        preemption.enabled = false;
     253        preemption.disable_count = 1;
    255254
    256255        // Initialize the event kernel
     
    295294        this.proc->preemption_alarm = &this.alarm;
    296295
    297         update_preemption( this.proc, this.proc->cltr->preemption_rate );
     296        update_preemption( this.proc, from_us(this.proc->cltr->preemption) );
    298297}
    299298
     
    331330        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    332331
    333         preemption_state.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     332        preemption.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
    334333        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 flag
     334        preemption.in_progress = false;                     // Clear the in progress flag
    336335
    337336        // Preemption can occur here
Note: See TracChangeset for help on using the changeset viewer.