Changes in src/Concurrency/Keywords.cc [ab8c6a6:69c5c00]
- File:
-
- 1 edited
-
src/Concurrency/Keywords.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
rab8c6a6 r69c5c00 46 46 } 47 47 48 // Only detects threads constructed with the keyword thread.49 inline static bool isThread( DeclarationWithType * decl ) {50 Type * baseType = decl->get_type()->stripDeclarator();51 StructInstType * instType = dynamic_cast<StructInstType *>( baseType );52 if ( nullptr == instType ) { return false; }53 return instType->baseStruct->is_thread();54 }55 56 48 //============================================================================================= 57 49 // Pass declarations … … 127 119 "get_thread", 128 120 "thread keyword requires threads to be in scope, add #include <thread.hfa>\n", 129 " ThreadCancelled",121 "", 130 122 true, 131 123 AggregateDecl::Thread … … 298 290 std::list<DeclarationWithType*> findMutexArgs( FunctionDecl*, bool & first ); 299 291 void validate( DeclarationWithType * ); 300 void addDtorStatements( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); 301 void addStatements( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); 302 void addThreadDtorStatements( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ); 292 void addDtorStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); 293 void addStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &); 303 294 304 295 static void implement( std::list< Declaration * > & translationUnit ) { … … 311 302 StructDecl* guard_decl = nullptr; 312 303 StructDecl* dtor_guard_decl = nullptr; 313 StructDecl* thread_guard_decl = nullptr;314 304 315 305 static std::unique_ptr< Type > generic_func; … … 811 801 bool first = false; 812 802 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl, first ); 813 bool constisDtor = CodeGen::isDestructor( decl->name );803 bool isDtor = CodeGen::isDestructor( decl->name ); 814 804 815 805 // Is this function relevant to monitors … … 859 849 860 850 // Instrument the body 861 if ( isDtor && isThread( mutexArgs.front() ) ) { 862 if( !thread_guard_decl ) { 863 SemanticError( decl, "thread destructor requires threads to be in scope, add #include <thread.hfa>\n" ); 864 } 865 addThreadDtorStatements( decl, body, mutexArgs ); 866 } 867 else if ( isDtor ) { 868 addDtorStatements( decl, body, mutexArgs ); 851 if( isDtor ) { 852 addDtorStatments( decl, body, mutexArgs ); 869 853 } 870 854 else { 871 addStat ements( decl, body, mutexArgs );855 addStatments( decl, body, mutexArgs ); 872 856 } 873 857 } … … 886 870 assert( !dtor_guard_decl ); 887 871 dtor_guard_decl = decl; 888 }889 else if( decl->name == "thread_dtor_guard_t" && decl->body ) {890 assert( !thread_guard_decl );891 thread_guard_decl = decl;892 872 } 893 873 } … … 928 908 } 929 909 930 void MutexKeyword::addDtorStat ements( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {910 void MutexKeyword::addDtorStatments( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) { 931 911 Type * arg_type = args.front()->get_type()->clone(); 932 912 arg_type->set_mutex( false ); … … 977 957 978 958 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 979 body->push_front( new DeclStmt( monitors ) ); 980 } 981 982 void MutexKeyword::addThreadDtorStatements( 983 FunctionDecl*, CompoundStmt * body, 984 const std::list<DeclarationWithType * > & args ) { 985 assert( args.size() == 1 ); 986 DeclarationWithType * arg = args.front(); 987 Type * arg_type = arg->get_type()->clone(); 988 assert( arg_type->get_mutex() ); 989 arg_type->set_mutex( false ); 990 991 // thread_dtor_guard_t __guard = { this, intptr( 0 ) }; 992 body->push_front( 993 new DeclStmt( new ObjectDecl( 994 "__guard", 995 noStorageClasses, 996 LinkageSpec::Cforall, 997 nullptr, 998 new StructInstType( 999 noQualifiers, 1000 thread_guard_decl 1001 ), 1002 new ListInit( 1003 { 1004 new SingleInit( new CastExpr( new VariableExpr( arg ), arg_type ) ), 1005 new SingleInit( new UntypedExpr( 1006 new NameExpr( "intptr" ), { 1007 new ConstantExpr( Constant::from_int( 0 ) ), 1008 } 1009 ) ), 1010 }, 1011 noDesignators, 1012 true 1013 ) 1014 )) 1015 ); 1016 } 1017 1018 void MutexKeyword::addStatements( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) { 959 body->push_front( new DeclStmt( monitors) ); 960 } 961 962 void MutexKeyword::addStatments( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) { 1019 963 ObjectDecl * monitors = new ObjectDecl( 1020 964 "__monitors",
Note:
See TracChangeset
for help on using the changeset viewer.