- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel_private.hfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel_private.hfa
r3e2b9c9 r320ec6fc 22 22 #include "stats.hfa" 23 23 24 #include "bits/random.hfa" 25 26 24 27 //----------------------------------------------------------------------------- 25 28 // Scheduler … … 50 53 51 54 55 struct event_kernel_t { 56 alarm_list_t alarms; 57 __spinlock_t lock; 58 }; 59 60 extern event_kernel_t * event_kernel; 61 62 struct __cfa_kernel_preemption_state_t { 63 bool enabled; 64 bool in_progress; 65 unsigned short disable_count; 66 }; 67 68 extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state __attribute__ ((tls_model ( "initial-exec" ))); 69 52 70 extern cluster * mainCluster; 53 71 … … 66 84 void __unpark( struct __processor_id_t *, $thread * thrd __cfaabi_dbg_ctx_param2 ); 67 85 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 88 void __kernel_io_startup ( cluster &, unsigned, bool ); 89 void __kernel_io_finish_start( cluster & ); 90 void __kernel_io_prepare_stop( cluster & ); 91 void __kernel_io_shutdown ( cluster &, bool ); 85 92 86 93 //----------------------------------------------------------------------------- 87 94 // Utils 95 #define KERNEL_STORAGE(T,X) __attribute((aligned(__alignof__(T)))) static char storage_##X[sizeof(T)] 96 97 static 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 106 void doregister( struct cluster & cltr ); 107 void unregister( struct cluster & cltr ); 108 88 109 void doregister( struct cluster * cltr, struct $thread & thrd ); 89 110 void unregister( struct cluster * cltr, struct $thread & thrd ); 90 91 //-----------------------------------------------------------------------------92 // I/O93 void ^?{}(io_context & this, bool );94 111 95 112 //======================================================================= … … 263 280 void ready_queue_shrink(struct cluster * cltr, int target); 264 281 282 //----------------------------------------------------------------------- 283 // IO user data 284 struct __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 265 308 266 309 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.