Changeset ecfd758 for libcfa/src/concurrency
- Timestamp:
- Apr 9, 2021, 2:11:43 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:
- b91bfde
- Parents:
- e07b589
- Location:
- libcfa/src/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
re07b589 recfd758 46 46 47 47 //----------------------------------------------------------------------------- 48 FORALL_DATA_INSTANCE(CoroutineCancelled, (coroutine_t &), (coroutine_t)) 49 50 forall(T &) 51 void mark_exception(CoroutineCancelled(T) *) {} 48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled); 52 49 53 50 forall(T &) … … 71 68 72 69 // TODO: Remove explitate vtable set once trac#186 is fixed. 73 CoroutineCancelled(T)except;74 except.virtual_table = & get_exception_vtable(&except);70 SomeCoroutineCancelled except; 71 except.virtual_table = &std_coroutine_cancelled; 75 72 except.the_coroutine = &cor; 76 73 except.the_exception = except; 77 throwResume except; 74 // Why does this need a cast? 75 throwResume (SomeCoroutineCancelled &)except; 78 76 79 77 except->virtual_table->free( except ); -
libcfa/src/concurrency/coroutine.hfa
re07b589 recfd758 22 22 //----------------------------------------------------------------------------- 23 23 // Exception thrown from resume when a coroutine stack is cancelled. 24 FORALL_DATA_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 24 EHM_EXCEPTION(SomeCoroutineCancelled)( 25 void * the_coroutine; 26 exception_t * the_exception; 27 ); 28 29 EHM_EXTERN_VTABLE(SomeCoroutineCancelled, std_coroutine_cancelled); 30 31 EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 25 32 coroutine_t * the_coroutine; 26 33 exception_t * the_exception; … … 37 44 // Anything that implements this trait can be resumed. 38 45 // Anything that is resumed is a coroutine. 39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION( CoroutineCancelled, (T))) {46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(SomeCoroutineCancelled)) { 40 47 void main(T & this); 41 48 $coroutine * get_coroutine(T & this); -
libcfa/src/concurrency/thread.cfa
re07b589 recfd758 62 62 } 63 63 64 FORALL_DATA_INSTANCE(ThreadCancelled, (thread_t &), (thread_t)) 64 EHM_VIRTUAL_TABLE(SomeThreadCancelled, std_thread_cancelled); 65 65 66 66 forall(T &) … … 73 73 forall(T &) 74 74 const char * msg(ThreadCancelled(T) *) { 75 return "ThreadCancelled ";75 return "ThreadCancelled(...)"; 76 76 } 77 77 78 78 forall(T &) 79 79 static void default_thread_cancel_handler(ThreadCancelled(T) & ) { 80 // Improve this error message, can I do formatting? 80 81 abort( "Unhandled thread cancellation.\n" ); 81 82 } 82 83 83 forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))) 84 static void default_thread_cancel_handler(SomeThreadCancelled & ) { 85 // Improve this error message, can I do formatting? 86 abort( "Unhandled thread cancellation.\n" ); 87 } 88 89 forall(T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled)) 84 90 void ?{}( thread_dtor_guard_t & this, 85 T & thrd, void(*cancelHandler)( ThreadCancelled(T)&)) {86 91 T & thrd, void(*cancelHandler)(SomeThreadCancelled &)) { 92 $monitor * m = get_monitor(thrd); 87 93 $thread * desc = get_thread(thrd); 88 94 89 95 // Setup the monitor guard 90 96 void (*dtor)(T& mutex this) = ^?{}; 91 bool join = cancelHandler != (void(*)( ThreadCancelled(T)&))0;97 bool join = cancelHandler != (void(*)(SomeThreadCancelled&))0; 92 98 (this.mg){&m, (void(*)())dtor, join}; 93 99 … … 103 109 } 104 110 desc->state = Cancelled; 105 void(*defaultResumptionHandler)( ThreadCancelled(T) &) =111 void(*defaultResumptionHandler)(SomeThreadCancelled &) = 106 112 join ? cancelHandler : default_thread_cancel_handler; 107 113 108 ThreadCancelled(T) except;109 114 // TODO: Remove explitate vtable set once trac#186 is fixed. 110 except.virtual_table = &get_exception_vtable(&except); 115 SomeThreadCancelled except; 116 except.virtual_table = &std_thread_cancelled; 111 117 except.the_thread = &thrd; 112 118 except.the_exception = __cfaehm_cancellation_exception( cancellation ); 113 throwResume except; 119 // Why is this cast required? 120 throwResume (SomeThreadCancelled &)except; 114 121 115 122 except.the_exception->virtual_table->free( except.the_exception ); … … 158 165 159 166 //----------------------------------------------------------------------------- 160 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION( ThreadCancelled, (T)))167 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled)) 161 168 T & join( T & this ) { 162 169 thread_dtor_guard_t guard = { this, defaultResumptionHandler }; -
libcfa/src/concurrency/thread.hfa
re07b589 recfd758 32 32 }; 33 33 34 FORALL_DATA_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) ( 34 EHM_EXCEPTION(SomeThreadCancelled) ( 35 void * the_thread; 36 exception_t * the_exception; 37 ); 38 39 EHM_EXTERN_VTABLE(SomeThreadCancelled, std_thread_cancelled); 40 41 EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) ( 35 42 thread_t * the_thread; 36 43 exception_t * the_exception; … … 79 86 }; 80 87 81 forall( T & | is_thread(T) | IS_EXCEPTION( ThreadCancelled, (T)) )82 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)( ThreadCancelled(T)&) );88 forall( T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled) ) 89 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(SomeThreadCancelled &) ); 83 90 void ^?{}( thread_dtor_guard_t & this ); 84 91 … … 125 132 //---------- 126 133 // join 127 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION( ThreadCancelled, (T)) )134 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled) ) 128 135 T & join( T & this ); 129 136
Note:
See TracChangeset
for help on using the changeset viewer.