Changes in / [578c09a:b39e6566]
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r578c09a rb39e6566 46 46 47 47 //----------------------------------------------------------------------------- 48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled); 49 48 50 forall(T &) 49 51 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) { … … 60 62 // This code should not be inlined. It is the error path on resume. 61 63 forall(T & | is_coroutine(T)) 62 void __cfaehm_cancelled_coroutine( 63 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) { 64 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) { 64 65 verify( desc->cancellation ); 65 66 desc->state = Cancelled; … … 67 68 68 69 // TODO: Remove explitate vtable set once trac#186 is fixed. 69 CoroutineCancelled(T)except;70 except.virtual_table = & _default_vtable;70 SomeCoroutineCancelled except; 71 except.virtual_table = &std_coroutine_cancelled; 71 72 except.the_coroutine = &cor; 72 73 except.the_exception = except; 73 74 // Why does this need a cast? 74 throwResume ( CoroutineCancelled(T)&)except;75 throwResume (SomeCoroutineCancelled &)except; 75 76 76 77 except->virtual_table->free( except ); … … 145 146 // Part of the Public API 146 147 // Not inline since only ever called once per coroutine 147 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })148 forall(T & | is_coroutine(T)) 148 149 void prime(T& cor) { 149 150 $coroutine* this = get_coroutine(cor); -
libcfa/src/concurrency/coroutine.hfa
r578c09a rb39e6566 22 22 //----------------------------------------------------------------------------- 23 23 // Exception thrown from resume when a coroutine stack is cancelled. 24 EHM_EXCEPTION(SomeCoroutineCancelled)( 25 void * the_coroutine; 26 exception_t * the_exception; 27 ); 28 29 EHM_EXTERN_VTABLE(SomeCoroutineCancelled, std_coroutine_cancelled); 30 24 31 EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) ( 25 32 coroutine_t * the_coroutine; … … 37 44 // Anything that implements this trait can be resumed. 38 45 // Anything that is resumed is a coroutine. 39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION( CoroutineCancelled, (T))) {46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(SomeCoroutineCancelled)) { 40 47 void main(T & this); 41 48 $coroutine * get_coroutine(T & this); … … 60 67 //----------------------------------------------------------------------------- 61 68 // Public coroutine API 62 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })69 forall(T & | is_coroutine(T)) 63 70 void prime(T & cor); 64 71 … … 130 137 131 138 forall(T & | is_coroutine(T)) 132 void __cfaehm_cancelled_coroutine( 133 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ); 139 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ); 134 140 135 141 // Resume implementation inlined for performance 136 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })142 forall(T & | is_coroutine(T)) 137 143 static inline T & resume(T & cor) { 138 144 // optimization : read TLS once and reuse it … … 164 170 $ctx_switch( src, dst ); 165 171 if ( unlikely(dst->cancellation) ) { 166 __cfaehm_cancelled_coroutine( cor, dst , _default_vtable);172 __cfaehm_cancelled_coroutine( cor, dst ); 167 173 } 168 174 -
libcfa/src/exception.hfa
r578c09a rb39e6566 142 142 _EHM_VTABLE_TYPE(exception_name) parameters const &) {} \ 143 143 144 #define _EHM_TRAIT_FUNCTION2(exception_name, forall_clause, parameters) \ 145 forall_clause _EHM_VTABLE_TYPE(exception_name) parameters const & \ 146 get_exception_vtable(exception_name parameters const & this) 147 144 148 #define __EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \ 145 149 forall_clause inline _EHM_VTABLE_TYPE(exception_name) parameters const & \ -
src/Concurrency/Keywords.cc
r578c09a rb39e6566 414 414 if ( type_decl && isDestructorFor( decl, type_decl ) ) 415 415 dtor_decl = decl; 416 else if ( vtable_name.empty() || !decl->has_body() ) 416 else if ( vtable_name.empty() ) 417 ; 418 else if( !decl->has_body() ) 417 419 ; 418 420 else if ( auto param = isMainFor( decl, cast_target ) ) { … … 426 428 std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) }; 427 429 ObjectDecl * vtable_object = Virtual::makeVtableInstance( 428 "_default_vtable_object_declaration",429 430 vtable_decl->makeInst( poly_args ), struct_type, nullptr ); 430 431 declsToAddAfter.push_back( vtable_object ); 431 declsToAddAfter.push_back(432 new ObjectDecl(433 Virtual::concurrentDefaultVTableName(),434 Type::Const,435 LinkageSpec::Cforall,436 /* bitfieldWidth */ nullptr,437 new ReferenceType( Type::Const, vtable_object->type->clone() ),438 new SingleInit( new VariableExpr( vtable_object ) )439 )440 );441 432 declsToAddAfter.push_back( Virtual::makeGetExceptionFunction( 442 433 vtable_object, except_decl->makeInst( std::move( poly_args ) ) … … 497 488 except_decl->makeInst( poly_args ) 498 489 ) ); 499 ObjectDecl * vtable_object = Virtual::makeVtableForward( 500 "_default_vtable_object_declaration", 501 vtable_decl->makeInst( move( poly_args ) ) ); 502 declsToAddBefore.push_back( vtable_object ); 503 declsToAddAfter.push_back( 504 new ObjectDecl( 505 Virtual::concurrentDefaultVTableName(), 506 Type::Const, 507 LinkageSpec::Cforall, 508 /* bitfieldWidth */ nullptr, 509 new ReferenceType( Type::Const, vtable_object->type->clone() ), 510 /* init */ nullptr 511 ) 512 ); 490 declsToAddBefore.push_back( Virtual::makeVtableForward( 491 vtable_decl->makeInst( move( poly_args ) ) ) ); 513 492 } 514 493 -
src/Virtual/Tables.cc
r578c09a rb39e6566 10 10 // Created On : Mon Aug 31 11:11:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Apr 21 15:36:00 202113 // Update Count : 212 // Last Modified On : Thr Apr 8 15:51:00 2021 13 // Update Count : 1 14 14 // 15 15 … … 50 50 } 51 51 52 std::string concurrentDefaultVTableName() {53 return "_default_vtable";54 }55 56 52 bool isVTableInstanceName( std::string const & name ) { 57 53 // There are some delicate length calculations here. … … 61 57 62 58 static ObjectDecl * makeVtableDeclaration( 63 std::string const & name,64 59 StructInstType * type, Initializer * init ) { 60 std::string const & name = instanceName( type->name ); 65 61 Type::StorageClasses storage = noStorageClasses; 66 62 if ( nullptr == init ) { … … 77 73 } 78 74 79 ObjectDecl * makeVtableForward( std::string const & name,StructInstType * type ) {75 ObjectDecl * makeVtableForward( StructInstType * type ) { 80 76 assert( type ); 81 return makeVtableDeclaration( name,type, nullptr );77 return makeVtableDeclaration( type, nullptr ); 82 78 } 83 79 84 80 ObjectDecl * makeVtableInstance( 85 std::string const & name, StructInstType * vtableType, 86 Type * objectType, Initializer * init ) { 81 StructInstType * vtableType, Type * objectType, Initializer * init ) { 87 82 assert( vtableType ); 88 83 assert( objectType ); … … 120 115 assert(false); 121 116 } 122 return makeVtableDeclaration( name,vtableType, init );117 return makeVtableDeclaration( vtableType, init ); 123 118 } 124 119 … … 172 167 } 173 168 169 ObjectDecl * makeTypeIdForward() { 170 return nullptr; 171 } 172 174 173 Attribute * linkonce( const std::string & subsection ) { 175 174 const std::string section = ".gnu.linkonce." + subsection; -
src/Virtual/Tables.h
r578c09a rb39e6566 10 10 // Created On : Mon Aug 31 11:07:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Apr 21 10:30:00 202113 // Update Count : 212 // Last Modified On : Thr Apr 8 15:55:00 2021 13 // Update Count : 1 14 14 // 15 15 … … 27 27 std::string instanceName( std::string const & vtable_name ); 28 28 std::string vtableInstanceName( std::string const & type_name ); 29 std::string concurrentDefaultVTableName();30 29 bool isVTableInstanceName( std::string const & name ); 31 30 32 ObjectDecl * makeVtableForward( 33 std::string const & name, StructInstType * vtableType ); 31 ObjectDecl * makeVtableForward( StructInstType * vtableType ); 34 32 /* Create a forward declaration of a vtable of the given type. 35 33 * vtableType node is consumed. 36 34 */ 37 35 38 ObjectDecl * makeVtableInstance( 39 std::string const & name, 40 StructInstType * vtableType, Type * objectType, 36 ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType, 41 37 Initializer * init = nullptr ); 42 38 /* Create an initialized definition of a vtable. -
tests/exceptions/cancel/coroutine.cfa
r578c09a rb39e6566 25 25 resume(cancel); 26 26 printf("4"); 27 } catchResume ( CoroutineCancelled(WillCancel)* error) {27 } catchResume (SomeCoroutineCancelled * error) { 28 28 printf("2"); 29 29 if ((virtual internal_error *)error->the_exception) {
Note: See TracChangeset
for help on using the changeset viewer.