- File:
-
- 1 edited
-
libcfa/src/concurrency/thread.hfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/thread.hfa
r8c50aed r09f357ec 31 31 }; 32 32 33 // define that satisfies the trait without using the thread keyword 34 #define DECL_THREAD(X) thread_desc* get_thread(X& this) __attribute__((const)) { return &this.__thrd; } void main(X& this) 35 36 // Inline getters for threads/coroutines/monitors 37 forall( dtype T | is_thread(T) ) 38 static inline coroutine_desc* get_coroutine(T & this) __attribute__((const)) { return &get_thread(this)->self_cor; } 33 #define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this) 39 34 40 35 forall( dtype T | is_thread(T) ) 41 static inline monitor_desc * get_monitor (T & this) __attribute__((const)) { return &get_thread(this)->self_mon; } 36 static inline coroutine_desc* get_coroutine(T & this) { 37 return &get_thread(this)->self_cor; 38 } 42 39 43 static inline coroutine_desc* get_coroutine(thread_desc * this) __attribute__((const)) { return &this->self_cor; } 44 static inline monitor_desc * get_monitor (thread_desc * this) __attribute__((const)) { return &this->self_mon; } 40 forall( dtype T | is_thread(T) ) 41 static inline monitor_desc* get_monitor(T & this) { 42 return &get_thread(this)->self_mon; 43 } 45 44 46 //----------------------------------------------------------------------------- 47 // forward declarations needed for threads 45 static inline coroutine_desc* get_coroutine(thread_desc * this) { 46 return &this->self_cor; 47 } 48 49 static inline monitor_desc* get_monitor(thread_desc * this) { 50 return &this->self_mon; 51 } 52 48 53 extern struct cluster * mainCluster; 49 54 … … 83 88 void ^?{}( scoped(T)& this ); 84 89 85 //----------------------------------------------------------------------------- 86 // Thread getters 90 void yield(); 91 void yield( unsigned times ); 92 87 93 static inline struct thread_desc * active_thread () { return TL_GET( this_thread ); } 88 89 //-----------------------------------------------------------------------------90 // Scheduler API91 92 //----------93 // Park thread: block until corresponding call to unpark, won't block if unpark is already called94 void park( void );95 96 //----------97 // Unpark a thread, if the thread is already blocked, schedule it98 // if the thread is not yet block, signal that it should rerun immediately99 void unpark( thread_desc * this );100 101 forall( dtype T | is_thread(T) )102 static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );}103 104 //----------105 // Yield: force thread to block and be rescheduled106 bool force_yield( enum __Preemption_Reason );107 108 static inline void yield() {109 force_yield(__MANUAL_PREEMPTION);110 }111 112 // Yield: yield N times113 static inline void yield( unsigned times ) {114 for( times ) {115 yield();116 }117 }118 94 119 95 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.