Changeset 1c01c58 for libcfa/src
- Timestamp:
- Sep 9, 2020, 5:03:40 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b9fa85b, c402739
- Parents:
- 2b7f6f0
- Location:
- libcfa/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r2b7f6f0 r1c01c58 47 47 48 48 //----------------------------------------------------------------------------- 49 FORALL_DATA_INSTANCE(CoroutineCancelled, 50 (dtype coroutine_t | sized(coroutine_t)), (coroutine_t)) 51 52 struct __cfaehm_node { 53 struct _Unwind_Exception unwind_exception; 54 struct __cfaehm_node * next; 55 int handler_index; 56 }; 57 58 forall(dtype T) 59 void mark_exception(CoroutineCancelled(T) *) {} 60 61 forall(dtype T | sized(T)) 62 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) { 63 dst->the_coroutine = src->the_coroutine; 64 dst->the_exception = src->the_exception; 65 } 66 67 forall(dtype T) 68 const char * msg(CoroutineCancelled(T) *) { 69 return "CoroutineCancelled(...)"; 70 } 71 72 // This code should not be inlined. It is the error path on resume. 73 forall(dtype T | is_coroutine(T)) 74 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) { 75 verify( desc->cancellation ); 76 desc->state = Cancelled; 77 exception_t * except = (exception_t *)(1 + (__cfaehm_node *)desc->cancellation); 78 79 CoroutineCancelled(T) except; 80 except.the_coroutine = &cor; 81 except.the_exception = except; 82 throwResume except; 83 84 except->virtual_table->free( except ); 85 free( desc->cancellation ); 86 desc->cancellation = 0p; 87 } 88 89 //----------------------------------------------------------------------------- 49 90 // Global state variables 50 91 … … 180 221 this->storage->limit = storage; 181 222 this->storage->base = (void*)((intptr_t)storage + size); 223 this->storage->exception_context.top_resume = 0p; 224 this->storage->exception_context.current_exception = 0p; 182 225 __attribute__((may_alias)) intptr_t * istorage = (intptr_t*)&this->storage; 183 226 *istorage |= userStack ? 0x1 : 0x0; -
libcfa/src/concurrency/coroutine.hfa
r2b7f6f0 r1c01c58 18 18 #include <assert.h> 19 19 #include "invoke.h" 20 #include "../exception.hfa" 21 22 //----------------------------------------------------------------------------- 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)) ( 27 coroutine_t * the_coroutine; 28 exception_t * the_exception; 29 ); 30 31 forall(dtype T) 32 void mark_exception(CoroutineCancelled(T) *); 33 34 forall(dtype T | sized(T)) 35 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src); 36 37 forall(dtype T) 38 const char * msg(CoroutineCancelled(T) *); 20 39 21 40 //----------------------------------------------------------------------------- … … 23 42 // Anything that implements this trait can be resumed. 24 43 // Anything that is resumed is a coroutine. 25 trait is_coroutine(dtype T) { 26 void main(T & this); 27 $coroutine * get_coroutine(T & this); 44 trait is_coroutine(dtype T | sized(T) 45 | is_resumption_exception(CoroutineCancelled(T)) 46 | VTABLE_ASSERTION(CoroutineCancelled, (T))) { 47 void main(T & this); 48 $coroutine * get_coroutine(T & this); 28 49 }; 29 50 … … 112 133 } 113 134 } 135 136 forall(dtype T | is_coroutine(T)) 137 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ); 114 138 115 139 // Resume implementation inlined for performance … … 145 169 // always done for performance testing 146 170 $ctx_switch( src, dst ); 171 if ( unlikely(dst->cancellation) ) { 172 __cfaehm_cancelled_coroutine( cor, dst ); 173 } 147 174 148 175 return cor; -
libcfa/src/concurrency/exception.cfa
r2b7f6f0 r1c01c58 57 57 58 58 STOP_AT_END_FUNCTION(coroutine_cancelstop, 59 // TODO: Instead pass information to the last resumer. 59 struct $coroutine * src = ($coroutine *)stop_param; 60 struct $coroutine * dst = src->last; 61 62 $ctx_switch( src, dst ); 60 63 abort(); 61 64 ) -
libcfa/src/concurrency/exception.hfa
r2b7f6f0 r1c01c58 18 18 #include "bits/defs.hfa" 19 19 #include "invoke.h" 20 struct _Unwind_Exception;21 22 // It must also be usable as a C header file.23 20 24 21 #ifdef __cforall 25 22 extern "C" { 23 24 #define HIDE_EXPORTS 26 25 #endif 26 #include "unwind.h" 27 27 28 28 struct exception_context_t * this_exception_context(void) OPTIONAL_THREAD; … … 32 32 33 33 #ifdef __cforall 34 #undef HIDE_EXPORTS 34 35 } 35 36 #endif -
libcfa/src/concurrency/invoke.h
r2b7f6f0 r1c01c58 68 68 }; 69 69 70 enum __Coroutine_State { Halted, Start, Primed, Blocked, Ready, Active };70 enum __Coroutine_State { Halted, Start, Primed, Blocked, Ready, Active, Cancelled }; 71 71 72 72 struct $coroutine { -
libcfa/src/exception.h
r2b7f6f0 r1c01c58 76 76 // implemented in the .c file either so they all have to be inline. 77 77 78 trait is_exception(dtype T) {78 trait is_exception(dtype exceptT) { 79 79 /* The first field must be a pointer to a virtual table. 80 80 * That virtual table must be a decendent of the base exception virtual tab$ 81 81 */ 82 void mark_exception( T *);82 void mark_exception(exceptT *); 83 83 // This is never used and should be a no-op. 84 84 }; 85 85 86 trait is_termination_exception(dtype T | is_exception(T)) {87 void defaultTerminationHandler( T &);86 trait is_termination_exception(dtype exceptT | is_exception(exceptT)) { 87 void defaultTerminationHandler(exceptT &); 88 88 }; 89 89 90 trait is_resumption_exception(dtype T | is_exception(T)) {91 void defaultResumptionHandler( T &);90 trait is_resumption_exception(dtype exceptT | is_exception(exceptT)) { 91 void defaultResumptionHandler(exceptT &); 92 92 }; 93 93 94 forall(dtype T | is_termination_exception(T))95 static inline void $throw( T & except) {94 forall(dtype exceptT | is_termination_exception(exceptT)) 95 static inline void $throw(exceptT & except) { 96 96 __cfaehm_throw_terminate( 97 97 (exception_t *)&except, … … 100 100 } 101 101 102 forall(dtype T | is_resumption_exception(T))103 static inline void $throwResume( T & except) {102 forall(dtype exceptT | is_resumption_exception(exceptT)) 103 static inline void $throwResume(exceptT & except) { 104 104 __cfaehm_throw_resume( 105 105 (exception_t *)&except, … … 108 108 } 109 109 110 forall(dtype T | is_exception(T))111 static inline void cancel_stack( T & except) __attribute__((noreturn)) {110 forall(dtype exceptT | is_exception(exceptT)) 111 static inline void cancel_stack(exceptT & except) __attribute__((noreturn)) { 112 112 __cfaehm_cancel_stack( (exception_t *)&except ); 113 113 } 114 114 115 forall(dtype T | is_exception(T))116 static inline void defaultTerminationHandler( T & except) {115 forall(dtype exceptT | is_exception(exceptT)) 116 static inline void defaultTerminationHandler(exceptT & except) { 117 117 return cancel_stack( except ); 118 118 } 119 119 120 forall(dtype T | is_exception(T))121 static inline void defaultResumptionHandler( T & except) {120 forall(dtype exceptT | is_exception(exceptT)) 121 static inline void defaultResumptionHandler(exceptT & except) { 122 122 throw except; 123 123 } -
libcfa/src/exception.hfa
r2b7f6f0 r1c01c58 192 192 size_t size; \ 193 193 void (*copy)(exception_name * this, exception_name * other); \ 194 void (* free)(exception_name & this); \194 void (*^?{})(exception_name & this); \ 195 195 const char * (*msg)(exception_name * this); \ 196 196 _CLOSE … … 213 213 size_t size; \ 214 214 void (*copy)(exception_name parameters * this, exception_name parameters * other); \ 215 void (* free)(exception_name parameters & this); \215 void (*^?{})(exception_name parameters & this); \ 216 216 const char * (*msg)(exception_name parameters * this); \ 217 217 _CLOSE
Note: See TracChangeset
for help on using the changeset viewer.