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

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

Rather large commit to get coroutine cancellation working.

This includes what you would expect, like new code in exceptions and a new
test, but it also includes a bunch of other things.

New coroutine state, currently just marks that the stack was cancelled. New
helpers for checking code structure and generating vtables. Changes to the
coroutine interface so resume may throw exceptions on cancellation, plus the
exception type that is thrown. Changes to the coroutine keyword generation to
generate exception code for each type of coroutine.

  • 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 : 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}
22
23#include "invoke.h"
24#include "exception.hfa"
25#include "coroutine.hfa"
26
27extern struct $thread * mainThread;
28
29// Common pattern for all the stop functions, wait until the end then act.
30#define STOP_AT_END_FUNCTION(NAME, ...) \
31static _Unwind_Reason_Code NAME( \
32                int version, \
33                _Unwind_Action actions, \
34                _Unwind_Exception_Class exception_class, \
35                struct _Unwind_Exception * unwind_exception, \
36                struct _Unwind_Context * unwind_context, \
37                void * stop_param) { \
38        verify(actions & _UA_CLEANUP_PHASE); \
39        verify(actions & _UA_FORCE_UNWIND); \
40        verify(!(actions & _UA_SEARCH_PHASE)); \
41        verify(!(actions & _UA_HANDLER_FRAME)); \
42        if ( actions & _UA_END_OF_STACK ) { \
43                __VA_ARGS__ \
44        } else { \
45                return _URC_NO_REASON; \
46        } \
47}
48
49STOP_AT_END_FUNCTION(main_cancelstop,
50        abort();
51)
52
53STOP_AT_END_FUNCTION(thread_cancelstop,
54        // TODO: Instead pass information to the joiner.
55        abort();
56)
57
58STOP_AT_END_FUNCTION(coroutine_cancelstop,
59        struct $coroutine * src = ($coroutine *)stop_param;
60        struct $coroutine * dst = src->last;
61
62        $ctx_switch( src, dst );
63        abort();
64)
65
66extern "C" {
67
68struct exception_context_t * this_exception_context(void) {
69        return &__get_stack( active_coroutine() )->exception_context;
70}
71
72_Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
73        _Unwind_Stop_Fn stop_func;
74        void * stop_param;
75
76        struct $thread * this_thread = TL_GET( this_thread );
77        if ( &this_thread->self_cor != this_thread->curr_cor ) {
78                struct $coroutine * cor = this_thread->curr_cor;
79                cor->cancellation = unwind_exception;
80
81                stop_func = coroutine_cancelstop;
82                stop_param = cor;
83        } else if ( mainThread == this_thread ) {
84                stop_func = main_cancelstop;
85                stop_param = (void *)0x22;
86        } else {
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.