Changes in / [eaeca5f:cfbab07]
- Files:
-
- 4 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
reaeca5f rcfbab07 59 59 containers/array.hfa \ 60 60 concurrency/iofwd.hfa \ 61 concurrency/mutex_stmt.hfa \62 61 containers/list.hfa \ 63 62 containers/queueLockFree.hfa \ -
libcfa/src/concurrency/monitor.cfa
reaeca5f rcfbab07 990 990 } 991 991 992 //-----------------------------------------------------------------------------993 // Enter routine for mutex stmt994 // Can't be accepted since a mutex stmt is effectively an anonymous routine995 // Thus we do not need a monitor group996 void lock( monitor$ * this ) {997 thread$ * thrd = active_thread();998 999 // Lock the monitor spinlock1000 lock( this->lock __cfaabi_dbg_ctx2 );1001 1002 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);1003 1004 if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {1005 abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );1006 }1007 else if( !this->owner ) {1008 // No one has the monitor, just take it1009 __set_owner( this, thrd );1010 1011 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" );1012 }1013 else if( this->owner == thrd) {1014 // We already have the monitor, just note how many times we took it1015 this->recursion += 1;1016 1017 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" );1018 }1019 else {1020 __cfaabi_dbg_print_safe( "Kernel : blocking \n" );1021 1022 // Some one else has the monitor, wait in line for it1023 /* paranoid */ verify( thrd->link.next == 0p );1024 append( this->entry_queue, thrd );1025 /* paranoid */ verify( thrd->link.next == 1p );1026 1027 unlock( this->lock );1028 park();1029 1030 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);1031 1032 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );1033 return;1034 }1035 1036 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);1037 1038 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );1039 /* paranoid */ verify( this->lock.lock );1040 1041 // Release the lock and leave1042 unlock( this->lock );1043 return;1044 }1045 1046 // Leave routine for mutex stmt1047 // Is just a wrapper around __leave for the is_lock trait to see1048 void unlock( monitor$ * this ) { __leave( this ); }1049 1050 992 // Local Variables: // 1051 993 // mode: c // -
libcfa/src/concurrency/monitor.hfa
reaeca5f rcfbab07 149 149 void __waitfor_internal( const __waitfor_mask_t & mask, int duration ); 150 150 151 // lock and unlock routines for mutex statements to use152 void lock( monitor$ * this );153 void unlock( monitor$ * this );154 155 151 // Local Variables: // 156 152 // mode: c // -
src/Concurrency/Keywords.cc
reaeca5f rcfbab07 93 93 ObjectDecl * addField( StructDecl * ); 94 94 void addRoutines( ObjectDecl *, FunctionDecl * ); 95 void addLockUnlockRoutines( StructDecl * );96 95 97 96 virtual bool is_target( StructDecl * decl ) = 0; … … 323 322 StructDecl* dtor_guard_decl = nullptr; 324 323 StructDecl* thread_guard_decl = nullptr; 325 StructDecl* lock_guard_decl = nullptr;326 324 327 325 static std::unique_ptr< Type > generic_func; … … 465 463 } 466 464 465 467 466 void ConcurrentSueKeyword::handle( StructDecl * decl ) { 468 467 if( ! decl->body ) return; … … 480 479 FunctionDecl * func = forwardDeclare( decl ); 481 480 ObjectDecl * field = addField( decl ); 482 483 // add get_.* routine484 481 addRoutines( field, func ); 485 // add lock/unlock routines to monitors for use by mutex stmt486 addLockUnlockRoutines( decl );487 482 } 488 483 … … 617 612 } 618 613 619 // This function adds the get_.* routine body for coroutines, monitors etc620 // after their corresponding struct has been made621 614 void ConcurrentSueKeyword::addRoutines( ObjectDecl * field, FunctionDecl * func ) { 622 615 CompoundStmt * statement = new CompoundStmt(); … … 641 634 642 635 declsToAddAfter.push_back( get_decl ); 643 }644 645 // Generates lock/unlock routines for monitors to be used by mutex stmts646 void ConcurrentSueKeyword::addLockUnlockRoutines( StructDecl * decl ) {647 // this routine will be called for all ConcurrentSueKeyword children so only continue if we are a monitor648 if ( !decl->is_monitor() ) return;649 650 FunctionType * lock_fn_type = new FunctionType( noQualifiers, false );651 FunctionType * unlock_fn_type = new FunctionType( noQualifiers, false );652 653 // create this ptr parameter for both routines654 ObjectDecl * this_decl = new ObjectDecl(655 "this",656 noStorageClasses,657 LinkageSpec::Cforall,658 nullptr,659 new ReferenceType(660 noQualifiers,661 new StructInstType(662 noQualifiers,663 decl664 )665 ),666 nullptr667 );668 669 lock_fn_type->get_parameters().push_back( this_decl->clone() );670 unlock_fn_type->get_parameters().push_back( this_decl->clone() );671 fixupGenerics(lock_fn_type, decl);672 fixupGenerics(unlock_fn_type, decl);673 674 delete this_decl;675 676 677 //////////////////////////////////////////////////////////////////////678 // The following generates this lock routine for all monitors679 /*680 void lock (monitor_t & this) {681 lock(get_monitor(this));682 }683 */684 FunctionDecl * lock_decl = new FunctionDecl(685 "lock",686 Type::Static,687 LinkageSpec::Cforall,688 lock_fn_type,689 nullptr,690 { },691 Type::Inline692 );693 694 UntypedExpr * get_monitor_lock = new UntypedExpr (695 new NameExpr( "get_monitor" ),696 { new VariableExpr( lock_fn_type->get_parameters().front() ) }697 );698 699 CompoundStmt * lock_statement = new CompoundStmt();700 lock_statement->push_back(701 new ExprStmt(702 new UntypedExpr (703 new NameExpr( "lock" ),704 {705 get_monitor_lock706 }707 )708 )709 );710 lock_decl->set_statements( lock_statement );711 712 //////////////////////////////////////////////////////////////////713 // The following generates this routine for all monitors714 /*715 void unlock (monitor_t & this) {716 unlock(get_monitor(this));717 }718 */719 FunctionDecl * unlock_decl = new FunctionDecl(720 "unlock",721 Type::Static,722 LinkageSpec::Cforall,723 unlock_fn_type,724 nullptr,725 { },726 Type::Inline727 );728 729 CompoundStmt * unlock_statement = new CompoundStmt();730 731 UntypedExpr * get_monitor_unlock = new UntypedExpr (732 new NameExpr( "get_monitor" ),733 { new VariableExpr( unlock_fn_type->get_parameters().front() ) }734 );735 736 unlock_statement->push_back(737 new ExprStmt(738 new UntypedExpr(739 new NameExpr( "unlock" ),740 {741 get_monitor_unlock742 }743 )744 )745 );746 unlock_decl->set_statements( unlock_statement );747 748 // pushes routines to declsToAddAfter to add at a later time749 declsToAddAfter.push_back( lock_decl );750 declsToAddAfter.push_back( unlock_decl );751 636 } 752 637 … … 1052 937 assert( !thread_guard_decl ); 1053 938 thread_guard_decl = decl; 1054 }1055 else if ( decl->name == "__mutex_stmt_lock_guard" && decl->body ) {1056 assert( !lock_guard_decl );1057 lock_guard_decl = decl;1058 939 } 1059 940 } … … 1200 1081 new PointerType( 1201 1082 noQualifiers, 1202 new TypeofType( noQualifiers, args.front()->clone() ) 1083 new StructInstType( 1084 noQualifiers, 1085 monitor_decl 1086 ) 1203 1087 ), 1204 1088 new ConstantExpr( Constant::from_ulong( args.size() ) ), … … 1209 1093 map_range < std::list<Initializer*> > ( args, [](Expression * var ){ 1210 1094 return new SingleInit( new UntypedExpr( 1211 new NameExpr( " __get_pointer" ),1095 new NameExpr( "get_monitor" ), 1212 1096 { var } 1213 1097 ) ); … … 1215 1099 ) 1216 1100 ); 1217 1218 StructInstType * lock_guard_struct = new StructInstType( noQualifiers, lock_guard_decl );1219 TypeExpr * lock_type_expr = new TypeExpr( new TypeofType( noQualifiers, args.front()->clone() ) );1220 1221 lock_guard_struct->parameters.push_back( lock_type_expr ) ;1222 1101 1223 1102 // in reverse order : … … 1229 1108 LinkageSpec::Cforall, 1230 1109 nullptr, 1231 lock_guard_struct, 1110 new StructInstType( 1111 noQualifiers, 1112 guard_decl 1113 ), 1232 1114 new ListInit( 1233 1115 { -
src/MakeLibCfa.h
reaeca5f rcfbab07 19 19 20 20 class Declaration; 21 namespace ast {22 struct TranslationUnit;23 }24 21 25 22 namespace LibCfa { 26 23 void makeLibCfa( std::list< Declaration* > &prelude ); 27 void makeLibCfa( ast::TranslationUnit & translationUnit );28 24 } // namespace LibCfa 29 25 -
src/Makefile.am
reaeca5f rcfbab07 23 23 CompilationState.h \ 24 24 MakeLibCfa.cc \ 25 MakeLibCfaNew.cpp \26 25 MakeLibCfa.h 27 26 -
src/Tuples/Tuples.h
reaeca5f rcfbab07 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Henry Xue12 // Last Modified On : Mon Aug 23 15:36:09 202113 // Update Count : 1 911 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 18 09:36:00 2019 13 // Update Count : 18 14 14 // 15 15 … … 39 39 /// expands z.[a, b.[x, y], c] into [z.a, z.b.x, z.b.y, z.c], inserting UniqueExprs as appropriate 40 40 void expandMemberTuples( std::list< Declaration * > & translationUnit ); 41 void expandMemberTuples( ast::TranslationUnit & translationUnit );42 41 43 42 /// replaces tuple-related elements, such as TupleType, TupleExpr, TupleAssignExpr, etc. -
src/Tuples/module.mk
reaeca5f rcfbab07 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Henry Xue13 ## Last Modified On : Mon Aug 23 15:36:09 202114 ## Update Count : 212 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Mon Jun 1 17:54:33 2015 14 ## Update Count : 1 15 15 ############################################################################### 16 16 … … 20 20 Tuples/TupleAssignment.cc \ 21 21 Tuples/TupleExpansion.cc \ 22 Tuples/TupleExpansionNew.cpp \23 22 Tuples/Tuples.cc \ 24 23 Tuples/Tuples.h -
src/main.cc
reaeca5f rcfbab07 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Henry Xue 12 // Last Modified On : Mon Aug 23 15:42:08202113 // Update Count : 65 012 // Last Modified On : Tue Jul 20 04:27:35 2021 13 // Update Count : 658 14 14 // 15 15 … … 335 335 PASS( "Fix Names", CodeGen::fixNames( translationUnit ) ); 336 336 PASS( "Gen Init", InitTweak::genInit( translationUnit ) ); 337 337 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) ); 338 338 if ( libcfap ) { 339 339 // generate the bodies of cfa library functions … … 365 365 } 366 366 auto transUnit = convert( move( translationUnit ) ); 367 368 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) );369 370 367 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 371 368 if ( exprp ) { … … 379 376 translationUnit = convert( move( transUnit ) ); 380 377 } else { 381 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );382 383 378 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 384 379 if ( exprp ) { -
tests/Makefile.am
reaeca5f rcfbab07 82 82 concurrent/clib_tls.c \ 83 83 exceptions/with-threads.hfa \ 84 exceptions/except-io.hfa 84 exceptions/except-io.hfa \ 85 unified_locking/mutex_test.hfa 85 86 86 87 dist-hook: -
tests/concurrent/mutexstmt/locks.cfa
reaeca5f rcfbab07 1 #include <mutex_stmt .hfa>1 #include <mutex_stmt_locks.hfa> 2 2 #include <locks.hfa> 3 3 … … 13 13 for (unsigned int i = 0; i < num_times; i++) { 14 14 mutex ( m1 ) count++; 15 mutex ( m1 ) { 15 mutex ( m1 ) { 16 16 assert(!insideFlag); 17 17 insideFlag = true; … … 65 65 printf("Start Test: single lock mutual exclusion\n"); 66 66 { 67 T_Mutex t[1 ];67 T_Mutex t[10]; 68 68 } 69 69 printf("End Test: single lock mutual exclusion\n"); -
tests/concurrent/mutexstmt/monitors.cfa
reaeca5f rcfbab07 1 1 #include <monitor.hfa> 2 #include <mutex_stmt.hfa>3 2 #include <stdio.h> 4 3 #include <stdlib.hfa> … … 14 13 bool insideFlag = false; 15 14 int count = 0; 16 bool startFlag = false;17 15 18 16 void main( T_Mutex & this ) {
Note: See TracChangeset
for help on using the changeset viewer.