- File:
-
- 1 edited
-
libcfa/src/concurrency/thread.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/thread.cfa
re873838 rb4b63e8 19 19 20 20 #include "kernel_private.hfa" 21 #include "exception.hfa"22 21 23 22 #define __CFA_INVOKE_PRIVATE__ … … 29 28 context{ 0p, 0p }; 30 29 self_cor{ name, storage, storageSize }; 31 ticket = TICKET_RUNNING;30 ticket = 1; 32 31 state = Start; 33 32 preempted = __NO_PREEMPTION; … … 59 58 } 60 59 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 117 60 //----------------------------------------------------------------------------- 118 61 // Starting and stopping threads … … 127 70 verify( this_thrd->context.SP ); 128 71 129 __schedule_thread( this_thrd);72 __schedule_thread( (__processor_id_t *)kernelTLS.this_processor, this_thrd); 130 73 enable_interrupts( __cfaabi_dbg_ctx ); 131 74 } … … 150 93 } 151 94 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 159 95 // Local Variables: // 160 96 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.