Changeset 342be43 for libcfa


Ignore:
Timestamp:
Oct 26, 2020, 5:10:02 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
cb25fc9
Parents:
ab8c6a6
Message:

Some exception clean-up that did not require any drastic changes.

Location:
libcfa/src
Files:
5 edited

Legend:

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

    rab8c6a6 r342be43  
    4949FORALL_DATA_INSTANCE(CoroutineCancelled, (dtype coroutine_t), (coroutine_t))
    5050
    51 struct __cfaehm_node {
    52         struct _Unwind_Exception unwind_exception;
    53         struct __cfaehm_node * next;
    54         int handler_index;
    55 };
    56 
    5751forall(dtype T)
    5852void mark_exception(CoroutineCancelled(T) *) {}
     
    6054forall(dtype T)
    6155void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
     56        dst->virtual_table = src->virtual_table;
    6257        dst->the_coroutine = src->the_coroutine;
    6358        dst->the_exception = src->the_exception;
     
    7469        verify( desc->cancellation );
    7570        desc->state = Cancelled;
    76         exception_t * except = (exception_t *)(1 + (__cfaehm_node *)desc->cancellation);
     71        exception_t * except = __cfaehm_cancellation_exception( desc->cancellation );
    7772
    7873        // TODO: Remove explitate vtable set once trac#186 is fixed.
  • libcfa/src/concurrency/exception.cfa

    rab8c6a6 r342be43  
    5454
    5555STOP_AT_END_FUNCTION(thread_cancelstop,
    56     __cfactx_thrd_leave();
    57     __cabi_abort( "Resumed cancelled thread" );
     56        __cfactx_thrd_leave();
     57        __cabi_abort( "Resumed cancelled thread" );
    5858)
    5959
  • libcfa/src/concurrency/exception.hfa

    rab8c6a6 r342be43  
    1616#pragma once
    1717
     18// This is an internal bridge between the two modes and must be C compatable.
     19
    1820#include "bits/defs.hfa"
    1921#include "invoke.h"
     
    3133                struct _Unwind_Exception * unwind_exception ) OPTIONAL_THREAD;
    3234
     35struct __cfaehm_node {
     36        struct _Unwind_Exception unwind_exception;
     37        struct __cfaehm_node * next;
     38        int handler_index;
     39};
     40
     41static inline exception_t * __cfaehm_cancellation_exception(
     42                struct _Unwind_Exception * unwind_exception ) {
     43        return (exception_t *)(1 + (struct __cfaehm_node *)unwind_exception);
     44}
     45
    3346#ifdef __cforall
    3447#undef HIDE_EXPORTS
  • libcfa/src/concurrency/thread.cfa

    rab8c6a6 r342be43  
    7373}
    7474
    75 struct __cfaehm_node {
    76         struct _Unwind_Exception unwind_exception;
    77         struct __cfaehm_node * next;
    78         int handler_index;
    79 };
    80 
    8175forall(dtype T)
    8276static void default_thread_cancel_handler(ThreadCancelled(T) & ) {
     
    9185        bool join = defaultResumptionHandler != (void(*)(ThreadCancelled(T)&))0;
    9286        (this.mg){&m, (void(*)())dtor, join};
    93         {
    94                 $thread * desc = get_thread(thrd);
    95                 struct _Unwind_Exception * cancellation = desc->self_cor.cancellation;
    96                 if ( likely(0p == cancellation) ) {
    97                         return;
    98                 } else if ( Cancelled == desc->state ) {
    99                         return;
    100                 }
    101                 desc->state = Cancelled;
    102                 if (!join) {
    103                         defaultResumptionHandler = default_thread_cancel_handler;
    104                 }
    105                 ThreadCancelled(T) except;
    106                 // TODO: Remove explitate vtable set once trac#186 is fixed.
    107                 except.virtual_table = &get_exception_vtable(&except);
    108                 except.the_thread = &thrd;
    109                 except.the_exception = (exception_t *)(1 + (__cfaehm_node *)cancellation);
    110                 throwResume except;
    11187
    112                 except.the_exception->virtual_table->free( except.the_exception );
    113                 free( cancellation );
    114                 desc->self_cor.cancellation = 0p;
     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;
    11595        }
     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;
    116111}
    117112
  • libcfa/src/exception.c

    rab8c6a6 r342be43  
    2424#include <bits/debug.hfa>
    2525#include "concurrency/invoke.h"
     26#include "concurrency/exception.hfa"
    2627#include "stdhdr/assert.h"
    2728
     
    113114
    114115// MEMORY MANAGEMENT =========================================================
    115 
    116 struct __cfaehm_node {
    117         struct _Unwind_Exception unwind_exception;
    118         struct __cfaehm_node * next;
    119         int handler_index;
    120 };
    121116
    122117#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
Note: See TracChangeset for help on using the changeset viewer.