Ignore:
File:
1 edited

Legend:

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

    rb69ea6b rd8548e2  
    2323}
    2424
     25#include "bits/cfatime.h"
    2526#include "bits/signal.h"
    2627
    27 //TODO move to defaults
    28 #define __CFA_DEFAULT_PREEMPTION__ 10000
    29 
    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)) {
    3233        return __CFA_DEFAULT_PREEMPTION__;
    3334}
     
    149150        // Disable interrupts by incrementing the counter
    150151        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;
    154155                verify( new_val < 65_000u );              // If this triggers someone is disabling interrupts without enabling them
    155156        }
     
    161162                thread_desc * thrd = this_thread;         // Cache the thread now since interrupts can start happening after the atomic add
    162163
    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;
    165166                verify( prev != 0u );                     // If this triggers someone is enabled already enabled interruptsverify( prev != 0u );
    166167
    167168                // Check if we need to prempt the thread because an interrupt was missed
    168169                if( prev == 1 ) {
    169                         preemption.enabled = true;
     170                        preemption_state.enabled = true;
    170171                        if( proc->pending_preemption ) {
    171172                                proc->pending_preemption = false;
     
    181182        // Don't execute any pending CtxSwitch even if counter reaches 0
    182183        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;
    185186                verifyf( prev != 0u, "Incremented from %u\n", prev );                     // If this triggers someone is enabled already enabled interrupts
    186187                if( prev == 1 ) {
    187                         preemption.enabled = true;
     188                        preemption_state.enabled = true;
    188189                }
    189190        }
     
    235236// If false : preemption is unsafe and marked as pending
    236237static inline bool preemption_ready() {
    237         bool ready = preemption.enabled && !preemption.in_progress; // Check if preemption is safe
     238        bool ready = preemption_state.enabled && !preemption_state.in_progress; // Check if preemption is safe
    238239        this_processor->pending_preemption = !ready;                        // Adjust the pending flag accordingly
    239240        return ready;
     
    250251
    251252        // 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;
    254255
    255256        // Initialize the event kernel
     
    294295        this.proc->preemption_alarm = &this.alarm;
    295296
    296         update_preemption( this.proc, from_us(this.proc->cltr->preemption) );
     297        update_preemption( this.proc, this.proc->cltr->preemption_rate );
    297298}
    298299
     
    330331        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    331332
    332         preemption.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     333        preemption_state.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
    333334        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 flag
     335        preemption_state.in_progress = false;                     // Clear the in progress flag
    335336
    336337        // Preemption can occur here
Note: See TracChangeset for help on using the changeset viewer.