source: libcfa/src/concurrency/exception.cfa @ 716b62c

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 716b62c was e84ab3d, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Step 1 of changing $thread to thread$

  • Property mode set to 100644
File size: 2.4 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 : Wed Oct 28 14:34:00 2020
13// Update Count     : 1
14//
15
16#define __cforall_thread__
17
18#include "exception.hfa"
19
20#include "coroutine.hfa"
21
22extern struct thread$ * mainThread;
23extern "C" {
24extern void __cfactx_thrd_leave();
25}
26
27// Common pattern for all the stop functions, wait until the end then act.
28#define STOP_AT_END_FUNCTION(NAME, ...) \
29static _Unwind_Reason_Code NAME( \
30                int version, \
31                _Unwind_Action actions, \
32                _Unwind_Exception_Class exception_class, \
33                struct _Unwind_Exception * unwind_exception, \
34                struct _Unwind_Context * unwind_context, \
35                void * stop_param) { \
36        verify(actions & _UA_CLEANUP_PHASE); \
37        verify(actions & _UA_FORCE_UNWIND); \
38        verify(!(actions & _UA_SEARCH_PHASE)); \
39        verify(!(actions & _UA_HANDLER_FRAME)); \
40        if ( actions & _UA_END_OF_STACK ) { \
41                __VA_ARGS__ \
42        } else { \
43                return _URC_NO_REASON; \
44        } \
45}
46
47STOP_AT_END_FUNCTION(main_cancelstop,
48        abort();
49)
50
51STOP_AT_END_FUNCTION(thread_cancelstop,
52        __cfactx_thrd_leave();
53        __cabi_abort( "Resumed cancelled thread" );
54)
55
56STOP_AT_END_FUNCTION(coroutine_cancelstop,
57        struct coroutine$ * src = (coroutine$ *)stop_param;
58        struct coroutine$ * dst = src->last;
59
60        $ctx_switch( src, dst );
61        abort();
62)
63
64extern "C" {
65
66struct exception_context_t * this_exception_context(void) {
67        return &__get_stack( active_coroutine() )->exception_context;
68}
69
70_Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
71        _Unwind_Stop_Fn stop_func;
72        void * stop_param;
73
74        struct thread$ * this_thread = active_thread();
75        if ( &this_thread->self_cor != this_thread->curr_cor ) {
76                struct coroutine$ * cor = this_thread->curr_cor;
77                cor->cancellation = unwind_exception;
78
79                stop_func = coroutine_cancelstop;
80                stop_param = cor;
81        } else if ( mainThread == this_thread ) {
82                stop_func = main_cancelstop;
83                stop_param = (void *)0x22;
84        } else {
85                this_thread->self_cor.cancellation = unwind_exception;
86
87                stop_func = thread_cancelstop;
88                stop_param = this_thread;
89        }
90
91        return _Unwind_ForcedUnwind( unwind_exception, stop_func, stop_param );
92}
93
94}
Note: See TracBrowser for help on using the repository browser.