Ignore:
File:
1 edited

Legend:

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

    r3e2b9c9 r320ec6fc  
    2222#include "stats.hfa"
    2323
     24#include "bits/random.hfa"
     25
     26
    2427//-----------------------------------------------------------------------------
    2528// Scheduler
     
    5053
    5154
     55struct event_kernel_t {
     56        alarm_list_t alarms;
     57        __spinlock_t lock;
     58};
     59
     60extern event_kernel_t * event_kernel;
     61
     62struct __cfa_kernel_preemption_state_t {
     63        bool enabled;
     64        bool in_progress;
     65        unsigned short disable_count;
     66};
     67
     68extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state __attribute__ ((tls_model ( "initial-exec" )));
     69
    5270extern cluster * mainCluster;
    5371
     
    6684void __unpark( struct __processor_id_t *, $thread * thrd __cfaabi_dbg_ctx_param2 );
    6785
    68 static inline bool __post(single_sem & this, struct __processor_id_t * id) {
    69         for() {
    70                 struct $thread * expected = this.ptr;
    71                 if(expected == 1p) return false;
    72                 if(expected == 0p) {
    73                         if(__atomic_compare_exchange_n(&this.ptr, &expected, 1p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    74                                 return false;
    75                         }
    76                 }
    77                 else {
    78                         if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    79                                 __unpark( id, expected __cfaabi_dbg_ctx2 );
    80                                 return true;
    81                         }
    82                 }
    83         }
    84 }
     86//-----------------------------------------------------------------------------
     87// I/O
     88void __kernel_io_startup     ( cluster &, unsigned, bool );
     89void __kernel_io_finish_start( cluster & );
     90void __kernel_io_prepare_stop( cluster & );
     91void __kernel_io_shutdown    ( cluster &, bool );
    8592
    8693//-----------------------------------------------------------------------------
    8794// Utils
     95#define KERNEL_STORAGE(T,X) __attribute((aligned(__alignof__(T)))) static char storage_##X[sizeof(T)]
     96
     97static inline uint64_t __tls_rand() {
     98        #if defined(__SIZEOF_INT128__)
     99                return __lehmer64( kernelTLS.rand_seed );
     100        #else
     101                return __xorshift64( kernelTLS.rand_seed );
     102        #endif
     103}
     104
     105
     106void doregister( struct cluster & cltr );
     107void unregister( struct cluster & cltr );
     108
    88109void doregister( struct cluster * cltr, struct $thread & thrd );
    89110void unregister( struct cluster * cltr, struct $thread & thrd );
    90 
    91 //-----------------------------------------------------------------------------
    92 // I/O
    93 void ^?{}(io_context & this, bool );
    94111
    95112//=======================================================================
     
    263280void ready_queue_shrink(struct cluster * cltr, int target);
    264281
     282//-----------------------------------------------------------------------
     283// IO user data
     284struct __io_user_data_t {
     285        int32_t result;
     286        $thread * thrd;
     287};
     288
     289//-----------------------------------------------------------------------
     290// Statics call at the end of each thread to register statistics
     291#if !defined(__CFA_NO_STATISTICS__)
     292        static inline struct __stats_t * __tls_stats() {
     293                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     294                /* paranoid */ verify( kernelTLS.this_stats );
     295                return kernelTLS.this_stats;
     296        }
     297
     298        #define __STATS__(in_kernel, ...) { \
     299                if( !(in_kernel) ) disable_interrupts(); \
     300                with( *__tls_stats() ) { \
     301                        __VA_ARGS__ \
     302                } \
     303                if( !(in_kernel) ) enable_interrupts( __cfaabi_dbg_ctx ); \
     304        }
     305#else
     306        #define __STATS__(in_kernel, ...)
     307#endif
    265308
    266309// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.