Changeset 7030dab for libcfa/src/concurrency/invoke.h
- Timestamp:
- Apr 6, 2020, 4:46:28 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- e3bc51c
- Parents:
- 71d6bd8 (diff), 057298e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/concurrency/invoke.h (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.h
r71d6bd8 r7030dab 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 22 18:19:13 201913 // Update Count : 4 012 // Last Modified On : Thu Dec 5 16:26:03 2019 13 // Update Count : 44 14 14 // 15 15 … … 47 47 extern "Cforall" { 48 48 extern __attribute__((aligned(128))) thread_local struct KernelThreadData { 49 struct thread_desc* volatile this_thread;49 struct $thread * volatile this_thread; 50 50 struct processor * volatile this_processor; 51 51 … … 92 92 }; 93 93 94 enum coroutine_state { Halted, Start, Inactive, Active, Primed }; 95 96 struct coroutine_desc { 97 // context that is switch during a CtxSwitch 94 enum coroutine_state { Halted, Start, Primed, Blocked, Ready, Active, Rerun }; 95 enum __Preemption_Reason { __NO_PREEMPTION, __ALARM_PREEMPTION, __POLL_PREEMPTION, __MANUAL_PREEMPTION }; 96 97 struct $coroutine { 98 // context that is switch during a __cfactx_switch 98 99 struct __stack_context_t context; 99 100 … … 108 109 109 110 // first coroutine to resume this one 110 struct coroutine_desc* starter;111 struct $coroutine * starter; 111 112 112 113 // last coroutine to resume this one 113 struct coroutine_desc* last;114 struct $coroutine * last; 114 115 115 116 // If non-null stack must be unwound with this exception … … 117 118 118 119 }; 120 121 static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2)); } 119 122 120 123 // struct which calls the monitor is accepting … … 127 130 }; 128 131 129 struct monitor_desc{132 struct $monitor { 130 133 // spinlock to protect internal data 131 134 struct __spinlock_t lock; 132 135 133 136 // current owner of the monitor 134 struct thread_desc* owner;137 struct $thread * owner; 135 138 136 139 // queue of threads that are blocked waiting for the monitor 137 __queue_t(struct thread_desc) entry_queue;140 __queue_t(struct $thread) entry_queue; 138 141 139 142 // stack of conditions to run next once we exit the monitor … … 152 155 struct __monitor_group_t { 153 156 // currently held monitors 154 __cfa_anonymous_object( __small_array_t( monitor_desc*) );157 __cfa_anonymous_object( __small_array_t($monitor*) ); 155 158 156 159 // last function that acquired monitors … … 158 161 }; 159 162 160 struct thread_desc{163 struct $thread { 161 164 // Core threading fields 162 // context that is switch during a CtxSwitch165 // context that is switch during a __cfactx_switch 163 166 struct __stack_context_t context; 164 167 165 168 // current execution status for coroutine 166 enum coroutine_state state; 169 volatile int state; 170 enum __Preemption_Reason preempted; 167 171 168 172 //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it 169 173 170 174 // coroutine body used to store context 171 struct coroutine_descself_cor;175 struct $coroutine self_cor; 172 176 173 177 // current active context 174 struct coroutine_desc* curr_cor;178 struct $coroutine * curr_cor; 175 179 176 180 // monitor body used for mutual exclusion 177 struct monitor_descself_mon;181 struct $monitor self_mon; 178 182 179 183 // pointer to monitor with sufficient lifetime for current monitors 180 struct monitor_desc* self_mon_p;184 struct $monitor * self_mon_p; 181 185 182 186 // pointer to the cluster on which the thread is running … … 188 192 // Link lists fields 189 193 // instrusive link field for threads 190 struct thread_desc* next;194 struct $thread * next; 191 195 192 196 struct { 193 struct thread_desc* next;194 struct thread_desc* prev;197 struct $thread * next; 198 struct $thread * prev; 195 199 } node; 196 }; 200 201 #ifdef __CFA_DEBUG__ 202 // previous function to park/unpark the thread 203 const char * park_caller; 204 enum coroutine_state park_result; 205 bool park_stale; 206 const char * unpark_caller; 207 enum coroutine_state unpark_result; 208 bool unpark_stale; 209 #endif 210 }; 211 212 #ifdef __CFA_DEBUG__ 213 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]); 214 #else 215 #define __cfaabi_dbg_record_thrd(x, y, z) 216 #endif 197 217 198 218 #ifdef __cforall 199 219 extern "Cforall" { 200 static inline thread_desc *& get_next( thread_desc & this) {220 static inline $thread *& get_next( $thread & this ) __attribute__((const)) { 201 221 return this.next; 202 222 } 203 223 204 static inline [ thread_desc *&, thread_desc *& ] __get( thread_desc & this) {224 static inline [$thread *&, $thread *& ] __get( $thread & this ) __attribute__((const)) { 205 225 return this.node.[next, prev]; 206 226 } 207 227 208 228 static inline void ?{}(__monitor_group_t & this) { 209 (this.data){ NULL};229 (this.data){0p}; 210 230 (this.size){0}; 211 231 (this.func){NULL}; 212 232 } 213 233 214 static inline void ?{}(__monitor_group_t & this, struct monitor_desc** data, __lock_size_t size, fptr_t func) {234 static inline void ?{}(__monitor_group_t & this, struct $monitor ** data, __lock_size_t size, fptr_t func) { 215 235 (this.data){data}; 216 236 (this.size){size}; … … 218 238 } 219 239 220 static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) {240 static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) __attribute__((const)) { 221 241 if( (lhs.data != 0) != (rhs.data != 0) ) return false; 222 242 if( lhs.size != rhs.size ) return false; … … 252 272 253 273 // assembler routines that performs the context switch 254 extern void CtxInvokeStub( void );255 extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");274 extern void __cfactx_invoke_stub( void ); 275 extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch"); 256 276 // void CtxStore ( void * this ) asm ("CtxStore"); 257 277 // void CtxRet ( void * dst ) asm ("CtxRet");
Note:
See TracChangeset
for help on using the changeset viewer.