Changeset c28ea4e for libcfa/src/concurrency/thread.cfa
- Timestamp:
- Nov 4, 2020, 2:56:30 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- eeb5023
- Parents:
- 4b30e8cc (diff), a3f5208a (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
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/thread.cfa
r4b30e8cc rc28ea4e 19 19 20 20 #include "kernel_private.hfa" 21 #include "exception.hfa" 21 22 22 23 #define __CFA_INVOKE_PRIVATE__ … … 28 29 context{ 0p, 0p }; 29 30 self_cor{ name, storage, storageSize }; 30 ticket = 1;31 ticket = TICKET_RUNNING; 31 32 state = Start; 32 33 preempted = __NO_PREEMPTION; … … 58 59 } 59 60 61 FORALL_DATA_INSTANCE(ThreadCancelled, (dtype thread_t), (thread_t)) 62 63 forall(dtype T) 64 void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) { 65 dst->virtual_table = src->virtual_table; 66 dst->the_thread = src->the_thread; 67 dst->the_exception = src->the_exception; 68 } 69 70 forall(dtype T) 71 const char * msg(ThreadCancelled(T) *) { 72 return "ThreadCancelled"; 73 } 74 75 forall(dtype T) 76 static void default_thread_cancel_handler(ThreadCancelled(T) & ) { 77 abort( "Unhandled thread cancellation.\n" ); 78 } 79 80 forall(dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))) 81 void ?{}( thread_dtor_guard_t & this, 82 T & thrd, void(*defaultResumptionHandler)(ThreadCancelled(T) &)) { 83 $monitor * m = get_monitor(thrd); 84 void (*dtor)(T& mutex this) = ^?{}; 85 bool join = defaultResumptionHandler != (void(*)(ThreadCancelled(T)&))0; 86 (this.mg){&m, (void(*)())dtor, join}; 87 88 // After the guard set-up and any wait, check for cancellation. 89 $thread * desc = get_thread(thrd); 90 struct _Unwind_Exception * cancellation = desc->self_cor.cancellation; 91 if ( likely( 0p == cancellation ) ) { 92 return; 93 } else if ( Cancelled == desc->state ) { 94 return; 95 } 96 desc->state = Cancelled; 97 if (!join) { 98 defaultResumptionHandler = default_thread_cancel_handler; 99 } 100 101 ThreadCancelled(T) except; 102 // TODO: Remove explitate vtable set once trac#186 is fixed. 103 except.virtual_table = &get_exception_vtable(&except); 104 except.the_thread = &thrd; 105 except.the_exception = __cfaehm_cancellation_exception( cancellation ); 106 throwResume except; 107 108 except.the_exception->virtual_table->free( except.the_exception ); 109 free( cancellation ); 110 desc->self_cor.cancellation = 0p; 111 } 112 113 void ^?{}( thread_dtor_guard_t & this ) { 114 ^(this.mg){}; 115 } 116 60 117 //----------------------------------------------------------------------------- 61 118 // Starting and stopping threads … … 70 127 verify( this_thrd->context.SP ); 71 128 72 __schedule_thread( (__processor_id_t *)kernelTLS.this_processor, this_thrd);129 __schedule_thread( this_thrd ); 73 130 enable_interrupts( __cfaabi_dbg_ctx ); 74 131 } … … 93 150 } 94 151 152 //----------------------------------------------------------------------------- 153 forall(dtype T | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))) 154 T & join( T & this ) { 155 thread_dtor_guard_t guard = { this, defaultResumptionHandler }; 156 return this; 157 } 158 95 159 // Local Variables: // 96 160 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.