Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/thread.cfa

    r6a77224 rb4b63e8  
    1919
    2020#include "kernel_private.hfa"
    21 #include "exception.hfa"
    2221
    2322#define __CFA_INVOKE_PRIVATE__
     
    2928        context{ 0p, 0p };
    3029        self_cor{ name, storage, storageSize };
    31         ticket = TICKET_RUNNING;
     30        ticket = 1;
    3231        state = Start;
    3332        preempted = __NO_PREEMPTION;
     
    5756        unregister(curr_cluster, this);
    5857        ^self_cor{};
    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){};
    11558}
    11659
     
    15093}
    15194
    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 
    15995// Local Variables: //
    16096// mode: c //
Note: See TracChangeset for help on using the changeset viewer.