source: libcfa/src/concurrency/exception.cfa @ ab8c6a6

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ab8c6a6 was ab8c6a6, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Thread Cancellation, a test for it and a required fix to Specialization.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// exception.cfa -- Exceptions in a concurrent environment.
8//
9// Author           : Andrew Beach
10// Created On       : Mon Aug 17 10:41:00 2020
11// Last Modified By : Andrew Beach
12// Last Modified On : Tue Aug 25 14:41:00 2020
13// Update Count     : 0
14//
15
16extern "C" {
17// use this define to make unwind.h play nice, definitely a hack
18#define HIDE_EXPORTS
19#include <unwind.h>
20#undef HIDE_EXPORTS
21
22extern void __cfactx_thrd_leave();
23}
24
25#include "invoke.h"
26#include "exception.hfa"
27#include "coroutine.hfa"
28
29extern struct $thread * mainThread;
30
31// Common pattern for all the stop functions, wait until the end then act.
32#define STOP_AT_END_FUNCTION(NAME, ...) \
33static _Unwind_Reason_Code NAME( \
34                int version, \
35                _Unwind_Action actions, \
36                _Unwind_Exception_Class exception_class, \
37                struct _Unwind_Exception * unwind_exception, \
38                struct _Unwind_Context * unwind_context, \
39                void * stop_param) { \
40        verify(actions & _UA_CLEANUP_PHASE); \
41        verify(actions & _UA_FORCE_UNWIND); \
42        verify(!(actions & _UA_SEARCH_PHASE)); \
43        verify(!(actions & _UA_HANDLER_FRAME)); \
44        if ( actions & _UA_END_OF_STACK ) { \
45                __VA_ARGS__ \
46        } else { \
47                return _URC_NO_REASON; \
48        } \
49}
50
51STOP_AT_END_FUNCTION(main_cancelstop,
52        abort();
53)
54
55STOP_AT_END_FUNCTION(thread_cancelstop,
56    __cfactx_thrd_leave();
57    __cabi_abort( "Resumed cancelled thread" );
58)
59
60STOP_AT_END_FUNCTION(coroutine_cancelstop,
61        struct $coroutine * src = ($coroutine *)stop_param;
62        struct $coroutine * dst = src->last;
63
64        $ctx_switch( src, dst );
65        abort();
66)
67
68extern "C" {
69
70struct exception_context_t * this_exception_context(void) {
71        return &__get_stack( active_coroutine() )->exception_context;
72}
73
74_Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
75        _Unwind_Stop_Fn stop_func;
76        void * stop_param;
77
78        struct $thread * this_thread = TL_GET( this_thread );
79        if ( &this_thread->self_cor != this_thread->curr_cor ) {
80                struct $coroutine * cor = this_thread->curr_cor;
81                cor->cancellation = unwind_exception;
82
83                stop_func = coroutine_cancelstop;
84                stop_param = cor;
85        } else if ( mainThread == this_thread ) {
86                stop_func = main_cancelstop;
87                stop_param = (void *)0x22;
88        } else {
89                this_thread->self_cor.cancellation = unwind_exception;
90
91                stop_func = thread_cancelstop;
92                stop_param = this_thread;
93        }
94
95        return _Unwind_ForcedUnwind( unwind_exception, stop_func, stop_param );
96}
97
98}
Note: See TracBrowser for help on using the repository browser.