Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel_private.h

    r2ac095d r4aa2fb2  
    1818#define KERNEL_PRIVATE_H
    1919
    20 #include "libhdr.h"
    21 
    2220#include "kernel"
    2321#include "thread"
     
    2523#include "alarm.h"
    2624
     25#include "libhdr.h"
    2726
    2827//-----------------------------------------------------------------------------
    2928// Scheduler
    30 
    31 extern "C" {
    32         void disable_interrupts();
    33         void enable_interrupts_noRF();
    34         void enable_interrupts( DEBUG_CTX_PARAM );
    35 }
    36 
    3729void ScheduleThread( thread_desc * );
    38 static inline void WakeThread( thread_desc * thrd ) {
    39         if( !thrd ) return;
    40 
    41         disable_interrupts();
    42         ScheduleThread( thrd );
    43         enable_interrupts( DEBUG_CTX );
    44 }
    4530thread_desc * nextThread(cluster * this);
    4631
    47 void BlockInternal(void);
    48 void BlockInternal(spinlock * lock);
    49 void BlockInternal(thread_desc * thrd);
    50 void BlockInternal(spinlock * lock, thread_desc * thrd);
    51 void BlockInternal(spinlock ** locks, unsigned short count);
    52 void BlockInternal(spinlock ** locks, unsigned short count, thread_desc ** thrds, unsigned short thrd_count);
     32void ScheduleInternal(void);
     33void ScheduleInternal(spinlock * lock);
     34void ScheduleInternal(thread_desc * thrd);
     35void ScheduleInternal(spinlock * lock, thread_desc * thrd);
     36void ScheduleInternal(spinlock ** locks, unsigned short count);
     37void ScheduleInternal(spinlock ** locks, unsigned short count, thread_desc ** thrds, unsigned short thrd_count);
    5338
    5439//-----------------------------------------------------------------------------
     
    7560extern cluster * systemCluster;
    7661extern system_proc_t * systemProcessor;
    77 extern volatile thread_local processor * this_processor;
    78 extern volatile thread_local coroutine_desc * this_coroutine;
    79 extern volatile thread_local thread_desc * this_thread;
    80 extern volatile thread_local unsigned short disable_preempt_count;
     62extern thread_local processor * this_processor;
     63
     64static inline void disable_interrupts() {
     65        __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, 1, __ATOMIC_SEQ_CST );
     66        assert( prev != (unsigned short) -1 );
     67}
     68
     69static inline void enable_interrupts_noRF() {
     70        __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, -1, __ATOMIC_SEQ_CST );
     71        verify( prev != (unsigned short) 0 );
     72}
     73
     74static inline void enable_interrupts() {
     75        __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, -1, __ATOMIC_SEQ_CST );
     76        verify( prev != (unsigned short) 0 );
     77        if( prev == 1 && this_processor->pending_preemption ) {
     78                ScheduleInternal( this_processor->current_thread );
     79                this_processor->pending_preemption = false;
     80        }
     81}
    8182
    8283//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.