Changeset e7d6968 for libcfa/src/concurrency
- Timestamp:
- Oct 23, 2020, 9:08:09 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c532847
- Parents:
- 37b7d95 (diff), 3aec25f (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. - Location:
- libcfa/src/concurrency
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r37b7d95 re7d6968 47 47 48 48 //----------------------------------------------------------------------------- 49 FORALL_DATA_INSTANCE(CoroutineCancelled, 50 (dtype coroutine_t | sized(coroutine_t)), (coroutine_t)) 49 FORALL_DATA_INSTANCE(CoroutineCancelled, (dtype coroutine_t), (coroutine_t)) 51 50 52 51 struct __cfaehm_node { … … 59 58 void mark_exception(CoroutineCancelled(T) *) {} 60 59 61 forall(dtype T | sized(T))60 forall(dtype T) 62 61 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) { 63 62 dst->the_coroutine = src->the_coroutine; … … 77 76 exception_t * except = (exception_t *)(1 + (__cfaehm_node *)desc->cancellation); 78 77 78 // TODO: Remove explitate vtable set once trac#186 is fixed. 79 79 CoroutineCancelled(T) except; 80 except.virtual_table = &get_exception_vtable(&except); 80 81 except.the_coroutine = &cor; 81 82 except.the_exception = except; … … 91 92 92 93 // minimum feasible stack size in bytes 93 #define MinStackSize 1000 94 static const size_t MinStackSize = 1000; 94 95 extern size_t __page_size; // architecture pagesize HACK, should go in proper runtime singleton 95 96 -
libcfa/src/concurrency/coroutine.hfa
r37b7d95 re7d6968 22 22 //----------------------------------------------------------------------------- 23 23 // Exception thrown from resume when a coroutine stack is cancelled. 24 // Should not have to be be sized (see trac #196). 25 FORALL_DATA_EXCEPTION(CoroutineCancelled, 26 (dtype coroutine_t | sized(coroutine_t)), (coroutine_t)) ( 24 FORALL_DATA_EXCEPTION(CoroutineCancelled, (dtype coroutine_t), (coroutine_t)) ( 27 25 coroutine_t * the_coroutine; 28 26 exception_t * the_exception; … … 30 28 31 29 forall(dtype T) 32 void mark_exception(CoroutineCancelled(T) *);33 34 forall(dtype T | sized(T))35 30 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src); 36 31 … … 42 37 // Anything that implements this trait can be resumed. 43 38 // Anything that is resumed is a coroutine. 44 trait is_coroutine(dtype T | sized(T) 45 | is_resumption_exception(CoroutineCancelled(T)) 46 | VTABLE_ASSERTION(CoroutineCancelled, (T))) { 39 trait is_coroutine(dtype T | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) { 47 40 void main(T & this); 48 41 $coroutine * get_coroutine(T & this); -
libcfa/src/concurrency/io.cfa
r37b7d95 re7d6968 134 134 int ret = 0; 135 135 if( need_sys_to_submit || need_sys_to_complete ) { 136 ret = syscall( __NR_io_uring_enter, ring.fd, to_submit, 0, flags, 0p, _NSIG / 8);136 ret = syscall( __NR_io_uring_enter, ring.fd, to_submit, 0, flags, (sigset_t *)0p, _NSIG / 8); 137 137 if( ret < 0 ) { 138 138 switch((int)errno) { -
libcfa/src/concurrency/io/call.cfa.in
r37b7d95 re7d6968 47 47 #include "kernel/fwd.hfa" 48 48 49 #if defined(CFA_HAVE_IOSQE_FIXED_FILE) && defined(CFA_HAVE_IOSQE_IO_DRAIN) && defined(CFA_HAVE_IOSQE_ASYNC) 50 #define REGULAR_FLAGS (IOSQE_FIXED_FILE | IOSQE_IO_DRAIN | IOSQE_ASYNC) 51 #elif defined(CFA_HAVE_IOSQE_FIXED_FILE) && defined(CFA_HAVE_IOSQE_ASYNC) 52 #define REGULAR_FLAGS (IOSQE_FIXED_FILE | IOSQE_ASYNC) 53 #elif defined(CFA_HAVE_IOSQE_FIXED_FILE) && defined(CFA_HAVE_IOSQE_IO_DRAIN) 54 #define REGULAR_FLAGS (IOSQE_FIXED_FILE | IOSQE_IO_DRAIN) 55 #elif defined(CFA_HAVE_IOSQE_IO_DRAIN) && defined(CFA_HAVE_IOSQE_ASYNC) 56 #define REGULAR_FLAGS (IOSQE_IO_DRAIN | IOSQE_ASYNC) 57 #elif defined(CFA_HAVE_IOSQE_FIXED_FILE) 58 #define REGULAR_FLAGS (IOSQE_FIXED_FILE) 59 #elif defined(CFA_HAVE_IOSQE_IO_DRAIN) 60 #define REGULAR_FLAGS (IOSQE_IO_DRAIN) 61 #elif defined(CFA_HAVE_IOSQE_ASYNC) 62 #define REGULAR_FLAGS (IOSQE_ASYNC) 63 #else 64 #define REGULAR_FLAGS (0) 65 #endif 66 67 #if defined(CFA_HAVE_IOSQE_IO_LINK) && defined(CFA_HAVE_IOSQE_IO_HARDLINK) 68 #define LINK_FLAGS (IOSQE_IO_LINK | IOSQE_IO_HARDLINK) 69 #elif defined(CFA_HAVE_IOSQE_IO_LINK) 70 #define LINK_FLAGS (IOSQE_IO_LINK) 71 #elif defined(CFA_HAVE_IOSQE_IO_HARDLINK) 72 #define LINK_FLAGS (IOSQE_IO_HARDLINK) 73 #else 74 #define LINK_FLAGS (0) 75 #endif 76 77 #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED) 78 #define SPLICE_FLAGS (SPLICE_F_FD_IN_FIXED) 79 #else 80 #define SPLICE_FLAGS (0) 81 #endif 49 static const __u8 REGULAR_FLAGS = 0 50 #if defined(CFA_HAVE_IOSQE_FIXED_FILE) 51 | IOSQE_FIXED_FILE 52 #endif 53 #if defined(CFA_HAVE_IOSQE_IO_DRAIN) 54 | IOSQE_IO_DRAIN 55 #endif 56 #if defined(CFA_HAVE_IOSQE_ASYNC) 57 | IOSQE_ASYNC 58 #endif 59 ; 60 61 static const __u32 LINK_FLAGS = 0 62 #if defined(CFA_HAVE_IOSQE_IO_LINK) 63 | IOSQE_IO_LINK 64 #endif 65 #if defined(CFA_HAVE_IOSQE_IO_HARDLINK) 66 | IOSQE_IO_HARDLINK 67 #endif 68 ; 69 70 static const __u32 SPLICE_FLAGS = 0 71 #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED) 72 | SPLICE_F_FD_IN_FIXED 73 #endif 74 ; 82 75 83 76 extern [* struct io_uring_sqe, __u32] __submit_alloc( struct __io_data & ring, __u64 data ); -
libcfa/src/concurrency/kernel.cfa
r37b7d95 re7d6968 252 252 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 253 253 /* paranoid */ verify( thrd_dst->context.SP ); 254 /* paranoid */ verify( thrd_dst->state != Halted ); 254 255 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor 255 256 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor … … 287 288 if(unlikely(thrd_dst->state == Halted)) { 288 289 // The thread has halted, it should never be scheduled/run again 289 // We may need to wake someone up here since 290 unpark( this->destroyer ); 291 this->destroyer = 0p; 290 // finish the thread 291 __thread_finish( thrd_dst ); 292 292 break RUNNING; 293 293 } … … 448 448 } 449 449 450 // KERNEL ONLY 451 void __leave_thread() { 452 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 453 returnToKernel(); 454 abort(); 450 extern "C" { 451 // Leave the thread monitor 452 // last routine called by a thread. 453 // Should never return 454 void __cfactx_thrd_leave() { 455 $thread * thrd = TL_GET( this_thread ); 456 $monitor * this = &thrd->self_mon; 457 458 // Lock the monitor now 459 lock( this->lock __cfaabi_dbg_ctx2 ); 460 461 disable_interrupts(); 462 463 thrd->state = Halted; 464 465 if( thrd != this->owner || this->recursion != 1) { abort( "Thread internal monitor has unbalanced recursion" ); } 466 467 // Leave the thread 468 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 469 returnToKernel(); 470 abort(); 471 472 // Control flow should never reach here! 473 } 455 474 } 456 475 -
libcfa/src/concurrency/kernel.hfa
r37b7d95 re7d6968 79 79 // Handle to pthreads 80 80 pthread_t kernel_thread; 81 82 // RunThread data83 // Action to do after a thread is ran84 $thread * destroyer;85 81 86 82 // Preemption data -
libcfa/src/concurrency/kernel/startup.cfa
r37b7d95 re7d6968 474 474 this.cltr = &_cltr; 475 475 full_proc = true; 476 destroyer = 0p;477 476 do_terminate = false; 478 477 preemption_alarm = 0p; -
libcfa/src/concurrency/kernel_private.hfa
r37b7d95 re7d6968 39 39 ; 40 40 41 // Block current thread andrelease/wake-up the following resources42 void __ leave_thread() __attribute__((noreturn));41 //release/wake-up the following resources 42 void __thread_finish( $thread * thrd ); 43 43 44 44 //----------------------------------------------------------------------------- -
libcfa/src/concurrency/monitor.cfa
r37b7d95 re7d6968 281 281 } 282 282 283 extern "C" { 284 // Leave the thread monitor 285 // last routine called by a thread. 286 // Should never return 287 void __cfactx_thrd_leave() { 288 $thread * thrd = TL_GET( this_thread ); 289 $monitor * this = &thrd->self_mon; 290 291 // Lock the monitor now 292 lock( this->lock __cfaabi_dbg_ctx2 ); 293 294 disable_interrupts(); 295 296 thrd->state = Halted; 297 298 /* paranoid */ verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", thrd, this->owner, this->recursion, this ); 299 300 // Leaving a recursion level, decrement the counter 301 this->recursion -= 1; 302 303 // If we haven't left the last level of recursion 304 // it must mean there is an error 305 if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); } 306 307 // Fetch the next thread, can be null 308 $thread * new_owner = next_thread( this ); 309 310 // Release the monitor lock 311 unlock( this->lock ); 312 313 // Unpark the next owner if needed 314 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 315 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 316 /* paranoid */ verify( ! kernelTLS.this_processor->destroyer ); 317 /* paranoid */ verify( thrd->state == Halted ); 318 319 kernelTLS.this_processor->destroyer = new_owner; 320 321 // Leave the thread 322 __leave_thread(); 323 324 // Control flow should never reach here! 325 } 283 void __thread_finish( $thread * thrd ) { 284 $monitor * this = &thrd->self_mon; 285 286 // Lock the monitor now 287 /* paranoid */ verify( this->lock.lock ); 288 /* paranoid */ verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", thrd, this->owner, this->recursion, this ); 289 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 290 /* paranoid */ verify( thrd->state == Halted ); 291 /* paranoid */ verify( this->recursion == 1 ); 292 293 // Leaving a recursion level, decrement the counter 294 this->recursion -= 1; 295 this->owner = 0p; 296 297 // Fetch the next thread, can be null 298 $thread * new_owner = next_thread( this ); 299 300 // Release the monitor lock 301 unlock( this->lock ); 302 303 // Unpark the next owner if needed 304 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 305 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 306 /* paranoid */ verify( thrd->state == Halted ); 307 unpark( new_owner ); 326 308 } 327 309 -
libcfa/src/concurrency/snzi.hfa
r37b7d95 re7d6968 36 36 static inline void depart( __snzi_node_t & ); 37 37 38 #define __snzi_half -1 38 static const int __snzi_half = -1; 39 39 40 40 //--------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.