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

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since f7fac4b was d119d613, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Reorganized the exception and concurrency overlap.

  • Property mode set to 100644
File size: 2.3 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 // TODO: Instead pass information to the last resumer.
60 abort();
61)
62
63extern "C" {
64
65struct exception_context_t * this_exception_context(void) {
66 return &__get_stack( active_coroutine() )->exception_context;
67}
68
69_Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
70 _Unwind_Stop_Fn stop_func;
71 void * stop_param;
72
73 struct $thread * this_thread = TL_GET( this_thread );
74 if ( &this_thread->self_cor != this_thread->curr_cor ) {
75 struct $coroutine * cor = this_thread->curr_cor;
76 cor->cancellation = unwind_exception;
77
78 stop_func = coroutine_cancelstop;
79 stop_param = cor;
80 } else if ( mainThread == this_thread ) {
81 stop_func = main_cancelstop;
82 stop_param = (void *)0x22;
83 } else {
84 stop_func = thread_cancelstop;
85 stop_param = this_thread;
86 }
87
88 return _Unwind_ForcedUnwind( unwind_exception, stop_func, stop_param );
89}
90
91}
Note: See TracBrowser for help on using the repository browser.