Changeset 83a071f9
- Timestamp:
- Aug 11, 2017, 10:10:26 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- fd344aa
- Parents:
- 8499c707
- Location:
- src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r8499c707 r83a071f9 291 291 LinkageSpec::Cforall, 292 292 nullptr, 293 new PointerType(293 new ReferenceType( 294 294 noQualifiers, 295 295 new StructInstType( … … 447 447 448 448 //Makes sure it's not a copy 449 PointerType* pty = dynamic_cast< PointerType * >( ty );450 449 ReferenceType* rty = dynamic_cast< ReferenceType * >( ty ); 451 if( ! pty && ! rty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg );450 if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg ); 452 451 453 452 //Make sure the we are pointing directly to a type 454 Type* base = pty ? pty->get_base() : rty->get_base(); 455 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 453 Type* base = rty->get_base(); 454 if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 455 if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg ); 456 456 457 457 //Make sure that typed isn't mutex -
src/libcfa/concurrency/coroutine
r8499c707 r83a071f9 26 26 // Anything that is resumed is a coroutine. 27 27 trait is_coroutine(dtype T) { 28 void main(T *this);29 coroutine_desc * get_coroutine(T *this);28 void main(T & this); 29 coroutine_desc * get_coroutine(T & this); 30 30 }; 31 31 32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X * this) { return &this->__cor; } void main(X*this)32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this) 33 33 34 34 //----------------------------------------------------------------------------- … … 45 45 46 46 forall(dtype T | is_coroutine(T)) 47 static inline void resume(T *cor);47 static inline void resume(T & cor); 48 48 49 49 forall(dtype T | is_coroutine(T)) 50 void prime(T *cor);50 void prime(T & cor); 51 51 52 52 //----------------------------------------------------------------------------- … … 87 87 // Resume implementation inlined for performance 88 88 forall(dtype T | is_coroutine(T)) 89 static inline void resume(T *cor) {89 static inline void resume(T & cor) { 90 90 coroutine_desc * src = this_coroutine; // optimization 91 91 coroutine_desc * dst = get_coroutine(cor); … … 93 93 if( unlikely(!dst->stack.base) ) { 94 94 create_stack(&dst->stack, dst->stack.size); 95 CtxStart( cor, CtxInvokeCoroutine);95 CtxStart(&cor, CtxInvokeCoroutine); 96 96 } 97 97 -
src/libcfa/concurrency/coroutine.c
r8499c707 r83a071f9 93 93 // Not inline since only ever called once per coroutine 94 94 forall(dtype T | is_coroutine(T)) 95 void prime(T *cor) {95 void prime(T& cor) { 96 96 coroutine_desc* this = get_coroutine(cor); 97 97 assert(this->state == Start); -
src/libcfa/concurrency/kernel.c
r8499c707 r83a071f9 139 139 } 140 140 141 void ?{}(processor & this, cluster * cltr, processorCtx_t *runner) {141 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) { 142 142 this.cltr = cltr; 143 143 (this.terminated){ 0 }; … … 148 148 this.kernel_thread = pthread_self(); 149 149 150 this.runner = runner;151 LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", runner);152 (*runner){ &this };150 this.runner = &runner; 151 LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", &runner); 152 runner{ &this }; 153 153 } 154 154 155 155 LIB_DEBUG_DO( bool validate( alarm_list_t * this ); ) 156 156 157 void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t *runner) {157 void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t & runner) { 158 158 (this.alarms){}; 159 159 (this.alarm_lock){}; … … 187 187 //============================================================================================= 188 188 //Main of the processor contexts 189 void main(processorCtx_t *runner) {190 processor * this = runner ->proc;189 void main(processorCtx_t & runner) { 190 processor * this = runner.proc; 191 191 192 192 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); … … 233 233 // from the processor coroutine to the target thread 234 234 void runThread(processor * this, thread_desc * dst) { 235 coroutine_desc * proc_cor = get_coroutine( this->runner);235 coroutine_desc * proc_cor = get_coroutine(*this->runner); 236 236 coroutine_desc * thrd_cor = get_coroutine(dst); 237 237 … … 315 315 // appropriate stack. 316 316 proc_cor_storage.__cor.state = Active; 317 main( &proc_cor_storage );317 main( proc_cor_storage ); 318 318 proc_cor_storage.__cor.state = Halted; 319 319 … … 455 455 mainThread = (thread_desc *)&mainThreadStorage; 456 456 current_stack_info_t info; 457 mainThread{ &info };457 (*mainThread){ &info }; 458 458 459 459 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); … … 461 461 // Initialize the system cluster 462 462 systemCluster = (cluster *)&systemClusterStorage; 463 systemCluster{};463 (*systemCluster){}; 464 464 465 465 LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n"); … … 468 468 // (the coroutine that contains the processing control flow) 469 469 systemProcessor = (system_proc_t *)&systemProcessorStorage; 470 (*systemProcessor){ systemCluster, (processorCtx_t *)&systemProcessorCtxStorage };470 (*systemProcessor){ systemCluster, *(processorCtx_t *)&systemProcessorCtxStorage }; 471 471 472 472 // Add the main thread to the ready queue … … 486 486 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 487 487 // mainThread is on the ready queue when this call is made. 488 resume( systemProcessor->proc.runner );488 resume( *systemProcessor->proc.runner ); 489 489 490 490 … … 514 514 // Destroy the system processor and its context in reverse order of construction 515 515 // These were manually constructed so we need manually destroy them 516 ^( systemProcessor->proc.runner){};516 ^(*systemProcessor->proc.runner){}; 517 517 ^(systemProcessor){}; 518 518 -
src/libcfa/concurrency/thread
r8499c707 r83a071f9 30 30 trait is_thread(dtype T) { 31 31 void ^?{}(T& mutex this); 32 void main(T *this);33 thread_desc* get_thread(T *this);32 void main(T& this); 33 thread_desc* get_thread(T& this); 34 34 }; 35 35 36 #define DECL_THREAD(X) thread_desc* get_thread(X * this) { return &this->__thrd; } void main(X*this)36 #define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this) 37 37 38 38 forall( dtype T | is_thread(T) ) 39 static inline coroutine_desc* get_coroutine(T *this) {39 static inline coroutine_desc* get_coroutine(T & this) { 40 40 return &get_thread(this)->cor; 41 41 } 42 42 43 43 forall( dtype T | is_thread(T) ) 44 static inline monitor_desc* get_monitor(T *this) {44 static inline monitor_desc* get_monitor(T & this) { 45 45 return &get_thread(this)->mon; 46 46 } … … 57 57 58 58 forall( dtype T | is_thread(T) ) 59 void __thrd_start( T *this );59 void __thrd_start( T & this ); 60 60 61 61 //----------------------------------------------------------------------------- -
src/libcfa/concurrency/thread.c
r8499c707 r83a071f9 51 51 void ?{}( scoped(T)& this ) { 52 52 (this.handle){}; 53 __thrd_start( &this.handle);53 __thrd_start(this.handle); 54 54 } 55 55 … … 57 57 void ?{}( scoped(T)& this, P params ) { 58 58 (this.handle){ params }; 59 __thrd_start( &this.handle);59 __thrd_start(this.handle); 60 60 } 61 61 … … 68 68 // Starting and stopping threads 69 69 forall( dtype T | is_thread(T) ) 70 void __thrd_start( T *this ) {70 void __thrd_start( T& this ) { 71 71 coroutine_desc* thrd_c = get_coroutine(this); 72 72 thread_desc* thrd_h = get_thread (this); … … 78 78 create_stack(&thrd_c->stack, thrd_c->stack.size); 79 79 this_coroutine = thrd_c; 80 CtxStart( this, CtxInvokeThread);80 CtxStart(&this, CtxInvokeThread); 81 81 assert( thrd_c->last->stack.context ); 82 82 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); -
src/libcfa/stdlib
r8499c707 r83a071f9 135 135 // allocation/deallocation and constructor/destructor, non-array types 136 136 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p ); 137 forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr );138 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );137 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr ); 138 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 139 139 140 140 // allocation/deallocation and constructor/destructor, array types -
src/libcfa/stdlib.c
r8499c707 r83a071f9 44 44 } // new 45 45 46 forall( dtype T | { void ^?{}( T & ); } )46 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) 47 47 void delete( T * ptr ) { 48 48 if ( ptr ) { // ignore null 49 ^ ptr{}; // run destructor49 ^(*ptr){}; // run destructor 50 50 free( ptr ); 51 51 } // if 52 52 } // delete 53 53 54 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } )54 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) 55 55 void delete( T * ptr, Params rest ) { 56 56 if ( ptr ) { // ignore null 57 ^ ptr{}; // run destructor57 ^(*ptr){}; // run destructor 58 58 free( ptr ); 59 59 } // if -
src/tests/coroutine.c
r8499c707 r83a071f9 25 25 } 26 26 27 void main( Fibonacci *this ) {27 void main( Fibonacci & this ) { 28 28 int fn1, fn2; // retained between resumes 29 this ->fn = 0; // case 030 fn1 = this ->fn;29 this.fn = 0; // case 0 30 fn1 = this.fn; 31 31 suspend(); // return to last resume 32 32 33 this ->fn = 1; // case 133 this.fn = 1; // case 1 34 34 fn2 = fn1; 35 fn1 = this ->fn;35 fn1 = this.fn; 36 36 suspend(); // return to last resume 37 37 38 38 for ( ;; ) { // general case 39 this ->fn = fn1 + fn2;39 this.fn = fn1 + fn2; 40 40 fn2 = fn1; 41 fn1 = this ->fn;41 fn1 = this.fn; 42 42 suspend(); // return to last resume 43 43 } // for 44 44 } 45 45 46 int next( Fibonacci *this ) {46 int next( Fibonacci & this ) { 47 47 resume( this ); // transfer to last suspend 48 return this ->fn;48 return this.fn; 49 49 } 50 50 … … 52 52 Fibonacci f1, f2; 53 53 for ( int i = 1; i <= 10; i += 1 ) { 54 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;54 sout | next( f1 ) | ' ' | next( f2 ) | endl; 55 55 } // for 56 56 } -
src/tests/monitor.c
r8499c707 r83a071f9 14 14 static global_t global; 15 15 16 void increment3( global_t *mutex this ) {17 this ->value += 1;16 void increment3( global_t & mutex this ) { 17 this.value += 1; 18 18 } 19 19 20 void increment2( global_t *mutex this ) {20 void increment2( global_t & mutex this ) { 21 21 increment3( this ); 22 22 } 23 23 24 void increment( global_t *mutex this ) {24 void increment( global_t & mutex this ) { 25 25 increment2( this ); 26 26 } … … 28 28 thread MyThread {}; 29 29 30 void main( MyThread *this ) {30 void main( MyThread & this ) { 31 31 for(int i = 0; i < 1_000_000; i++) { 32 increment( &global );32 increment( global ); 33 33 } 34 34 } -
src/tests/multi-monitor.c
r8499c707 r83a071f9 10 10 static monitor_t m1, m2, m3; 11 11 12 void increment( monitor_t * mutex p1, monitor_t * mutex p2, int *value ) {13 *value += 1;12 void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) { 13 value += 1; 14 14 } 15 15 16 struct MyThread { 17 thread_desc __thrd; 16 thread MyThread { 18 17 int target; 19 18 }; 20 21 DECL_THREAD(MyThread);22 19 23 20 void ?{}( MyThread & this, int target ) { … … 27 24 void ^?{}( MyThread & mutex this ) {} 28 25 29 void main( MyThread *this ) {26 void main( MyThread & this ) { 30 27 for(int i = 0; i < 1000000; i++) { 31 choose(this ->target) {32 case 0: increment( &m1, &m2, &global12 );33 case 1: increment( &m2, &m3, &global23 );34 case 2: increment( &m1, &m3, &global13 );28 choose(this.target) { 29 case 0: increment( m1, m2, global12 ); 30 case 1: increment( m2, m3, global23 ); 31 case 2: increment( m1, m3, global13 ); 35 32 } 36 33 } 34 } 35 36 forall(dtype T | sized(T) | { void ^?{}(T & mutex); }) 37 void delete_mutex(T * x) { 38 ^(*x){}; 39 free(x); 37 40 } 38 41 … … 40 43 processor p; 41 44 { 42 scoped(MyThread)* f[6];45 MyThread * f[6]; 43 46 for(int i = 0; i < 6; i++) { 44 f[i] = (*(scoped(MyThread) *)malloc()){ i % 3 };47 f[i] = new(i % 3); 45 48 } 46 49 47 50 for(int i = 0; i < 6; i++) { 48 delete ( f[i] );51 delete_mutex( f[i] ); 49 52 } 50 53 } -
src/tests/preempt.c
r8499c707 r83a071f9 20 20 } 21 21 22 void main(worker_t *this) {22 void main(worker_t & this) { 23 23 while(counter < 1000) { 24 if( (counter % 7) == this ->value ) {24 if( (counter % 7) == this.value ) { 25 25 int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST); 26 26 if( (next % 100) == 0 ) printf("%d\n", next); -
src/tests/sched-int-barge.c
r8499c707 r83a071f9 39 39 thread Threads {}; 40 40 41 bool logicC( global_t * mutex a, global_t * mutex b, global_data_t *mutex c ) {42 c ->counter++;41 bool logicC( global_t & mutex a, global_t & mutex b, global_data_t & mutex c ) { 42 c.counter++; 43 43 44 if( (c ->counter % 1000) == 0 ) sout | c->counter | endl;44 if( (c.counter % 1000) == 0 ) sout | c.counter | endl; 45 45 46 int action = c ->counter % 10;46 int action = c.counter % 10; 47 47 48 48 if( action == 0 ) { 49 c ->do_signal = max( ((unsigned)rand48()) % 10, 1);50 c ->do_wait1 = ((unsigned)rand48()) % (c->do_signal);51 c ->do_wait2 = ((unsigned)rand48()) % (c->do_signal);49 c.do_signal = max( ((unsigned)rand48()) % 10, 1); 50 c.do_wait1 = ((unsigned)rand48()) % (c.do_signal); 51 c.do_wait2 = ((unsigned)rand48()) % (c.do_signal); 52 52 53 // if(c ->do_wait1 == c->do_wait2) sout | "Same" | endl;53 // if(c.do_wait1 == c.do_wait2) sout | "Same" | endl; 54 54 } 55 55 56 if( action == c ->do_wait1 || action == c->do_wait2 ) {57 c ->state = WAIT;56 if( action == c.do_wait1 || action == c.do_wait2 ) { 57 c.state = WAIT; 58 58 wait( &cond ); 59 59 60 if(c ->state != SIGNAL) {61 sout | "ERROR Barging detected" | c ->counter | endl;60 if(c.state != SIGNAL) { 61 sout | "ERROR Barging detected" | c.counter | endl; 62 62 abort(); 63 63 } 64 64 } 65 else if( action == c ->do_signal ) {66 c ->state = SIGNAL;65 else if( action == c.do_signal ) { 66 c.state = SIGNAL; 67 67 68 68 signal( &cond ); … … 70 70 } 71 71 else { 72 c ->state = BARGE;72 c.state = BARGE; 73 73 } 74 74 75 if( c ->counter >= 100_000 ) c->done = true;76 return !c ->done;75 if( c.counter >= 100_000 ) c.done = true; 76 return !c.done; 77 77 } 78 78 79 bool logicB( global_t * mutex a, global_t *mutex b ) {80 return logicC(a, b, &globalC);79 bool logicB( global_t & mutex a, global_t & mutex b ) { 80 return logicC(a, b, globalC); 81 81 } 82 82 83 bool logicA( global_t *mutex a ) {84 return logicB(a, &globalB);83 bool logicA( global_t & mutex a ) { 84 return logicB(a, globalB); 85 85 } 86 86 87 void main( Threads *this ) {88 while( logicA( &globalA) ) { yield(); };87 void main( Threads & this ) { 88 while( logicA(globalA) ) { yield(); }; 89 89 } 90 90 -
src/tests/sched-int-block.c
r8499c707 r83a071f9 30 30 31 31 //------------------------------------------------------------------------------ 32 void wait_op( global_data_t * mutex a, global_data_t *mutex b, unsigned i ) {32 void wait_op( global_data_t & mutex a, global_data_t & mutex b, unsigned i ) { 33 33 wait( &cond, (uintptr_t)this_thread ); 34 34 35 35 yield( ((unsigned)rand48()) % 10 ); 36 36 37 if(a ->last_thread != a->last_signaller || b->last_thread != b->last_signaller ) {38 sout | "ERROR Barging detected, expected" | a ->last_signaller | b->last_signaller | "got" | a->last_thread | b->last_thread | endl;37 if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) { 38 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl; 39 39 abort(); 40 40 } 41 41 42 a ->last_thread = b->last_thread = this_thread;42 a.last_thread = b.last_thread = this_thread; 43 43 44 44 yield( ((unsigned)rand48()) % 10 ); … … 46 46 47 47 thread Waiter {}; 48 void main( Waiter *this ) {48 void main( Waiter & this ) { 49 49 for( int i = 0; i < N; i++ ) { 50 wait_op( &globalA, &globalB, i );50 wait_op( globalA, globalB, i ); 51 51 } 52 52 } 53 53 54 54 //------------------------------------------------------------------------------ 55 void signal_op( global_data_t * mutex a, global_data_t *mutex b ) {55 void signal_op( global_data_t & mutex a, global_data_t & mutex b ) { 56 56 yield( ((unsigned)rand48()) % 10 ); 57 57 58 a->last_thread = b->last_thread = a->last_signaller = b->last_signaller= this_thread;58 [a.last_thread, b.last_thread, a.last_signaller, b.last_signaller] = this_thread; 59 59 60 60 if( !is_empty( &cond ) ) { … … 69 69 yield( ((unsigned)rand48()) % 10 ); 70 70 71 if(a ->last_thread != next || b->last_thread != next) {72 sout | "ERROR Barging detected, expected" | next | "got" | a ->last_thread | b->last_thread | endl;71 if(a.last_thread != next || b.last_thread != next) { 72 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl; 73 73 abort(); 74 74 } … … 78 78 79 79 thread Signaller {}; 80 void main( Signaller *this ) {80 void main( Signaller & this ) { 81 81 while( !done ) { 82 signal_op( &globalA, &globalB );82 signal_op( globalA, globalB ); 83 83 } 84 84 } 85 85 86 86 //------------------------------------------------------------------------------ 87 void barge_op( global_data_t *mutex a ) {88 a ->last_thread = this_thread;87 void barge_op( global_data_t & mutex a ) { 88 a.last_thread = this_thread; 89 89 } 90 90 91 91 thread Barger {}; 92 void main( Barger *this ) {92 void main( Barger & this ) { 93 93 for( unsigned i = 0; !done; i++ ) { 94 94 //Choose some monitor to barge into with some irregular pattern 95 95 bool choose_a = (i % 13) > (i % 17); 96 barge_op( choose_a ? &globalA : &globalB ); 96 if ( choose_a ) barge_op( globalA ); 97 else barge_op( globalB ); 97 98 } 98 99 } -
src/tests/sched-int-disjoint.c
r8499c707 r83a071f9 35 35 //------------------------------------------------------------------------------ 36 36 // Barging logic 37 void barge( global_data_t *mutex d ) {38 d ->state = BARGE;37 void barge( global_data_t & mutex d ) { 38 d.state = BARGE; 39 39 } 40 40 41 41 thread Barger {}; 42 42 43 void main( Barger *this ) {43 void main( Barger & this ) { 44 44 while( !all_done ) { 45 barge( &data );45 barge( data ); 46 46 yield(); 47 47 } … … 50 50 //------------------------------------------------------------------------------ 51 51 // Waiting logic 52 bool wait( global_t * mutex m, global_data_t *mutex d ) {52 bool wait( global_t & mutex m, global_data_t & mutex d ) { 53 53 wait( &cond ); 54 if( d ->state != SIGNAL ) {54 if( d.state != SIGNAL ) { 55 55 sout | "ERROR barging!" | endl; 56 56 } 57 57 58 d ->counter++;58 d.counter++; 59 59 60 if( (d ->counter % 1000) == 0 ) sout | d->counter | endl;60 if( (d.counter % 1000) == 0 ) sout | d.counter | endl; 61 61 62 return d ->counter < N;62 return d.counter < N; 63 63 } 64 64 65 65 thread Waiter {}; 66 66 67 void main( Waiter *this ) {68 while( wait( &mut, &data ) ) { yield(); }67 void main( Waiter & this ) { 68 while( wait( mut, data ) ) { yield(); } 69 69 } 70 70 … … 72 72 //------------------------------------------------------------------------------ 73 73 // Signalling logic 74 void signal( condition * cond, global_t * mutex a, global_data_t *mutex b ) {75 b ->state = SIGNAL;74 void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) { 75 b.state = SIGNAL; 76 76 signal( cond ); 77 77 } 78 78 79 void logic( global_t *mutex a ) {80 signal( &cond, a, &data );79 void logic( global_t & mutex a ) { 80 signal( &cond, a, data ); 81 81 82 82 yield( (unsigned)rand48() % 10 ); … … 91 91 thread Signaller {}; 92 92 93 void main( Signaller *this ) {93 void main( Signaller & this ) { 94 94 while( !all_done ) { 95 logic( &mut );95 logic( mut ); 96 96 yield(); 97 97 } -
src/tests/sched-int-wait.c
r8499c707 r83a071f9 27 27 //---------------------------------------------------------------------------------------------------- 28 28 // Tools 29 void signal( condition * cond, global_t * mutex a, global_t *mutex b ) {29 void signal( condition * cond, global_t & mutex a, global_t & mutex b ) { 30 30 signal( cond ); 31 31 } 32 32 33 void signal( condition * cond, global_t * mutex a, global_t * mutex b, global_t *mutex c ) {33 void signal( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 34 34 signal( cond ); 35 35 } 36 36 37 void wait( condition * cond, global_t * mutex a, global_t *mutex b ) {37 void wait( condition * cond, global_t & mutex a, global_t & mutex b ) { 38 38 wait( cond ); 39 39 } 40 40 41 void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t *mutex c ) {41 void wait( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 42 42 wait( cond ); 43 43 } … … 45 45 //---------------------------------------------------------------------------------------------------- 46 46 // Signaler 47 void main( Signaler *this ) {47 void main( Signaler & this ) { 48 48 49 49 while( waiter_left != 0 ) { … … 51 51 switch( action ) { 52 52 case 0: 53 signal( &condABC, &globalA, &globalB, &globalC );53 signal( &condABC, globalA, globalB, globalC ); 54 54 break; 55 55 case 1: 56 signal( &condAB , &globalA, &globalB );56 signal( &condAB , globalA, globalB ); 57 57 break; 58 58 case 2: 59 signal( &condBC , &globalB, &globalC );59 signal( &condBC , globalB, globalC ); 60 60 break; 61 61 case 3: 62 signal( &condAC , &globalA, &globalC );62 signal( &condAC , globalA, globalC ); 63 63 break; 64 64 default: … … 72 72 //---------------------------------------------------------------------------------------------------- 73 73 // Waiter ABC 74 void main( WaiterABC *this ) {74 void main( WaiterABC & this ) { 75 75 for( int i = 0; i < N; i++ ) { 76 wait( &condABC, &globalA, &globalB, &globalC );76 wait( &condABC, globalA, globalB, globalC ); 77 77 } 78 78 … … 82 82 //---------------------------------------------------------------------------------------------------- 83 83 // Waiter AB 84 void main( WaiterAB *this ) {84 void main( WaiterAB & this ) { 85 85 for( int i = 0; i < N; i++ ) { 86 wait( &condAB , &globalA, &globalB );86 wait( &condAB , globalA, globalB ); 87 87 } 88 88 … … 92 92 //---------------------------------------------------------------------------------------------------- 93 93 // Waiter AC 94 void main( WaiterAC *this ) {94 void main( WaiterAC & this ) { 95 95 for( int i = 0; i < N; i++ ) { 96 wait( &condAC , &globalA, &globalC );96 wait( &condAC , globalA, globalC ); 97 97 } 98 98 … … 102 102 //---------------------------------------------------------------------------------------------------- 103 103 // Waiter BC 104 void main( WaiterBC *this ) {104 void main( WaiterBC & this ) { 105 105 for( int i = 0; i < N; i++ ) { 106 wait( &condBC , &globalB, &globalC );106 wait( &condBC , globalB, globalC ); 107 107 } 108 108 -
src/tests/thread.c
r8499c707 r83a071f9 7 7 thread Second { semaphore* lock; }; 8 8 9 void ?{}( First & this, semaphore * lock ) { this.lock =lock; }10 void ?{}( Second & this, semaphore * lock ) { this.lock =lock; }9 void ?{}( First & this, semaphore & lock ) { this.lock = &lock; } 10 void ?{}( Second & this, semaphore & lock ) { this.lock = &lock; } 11 11 12 void main(First *this) {12 void main(First& this) { 13 13 for(int i = 0; i < 10; i++) { 14 14 sout | "First : Suspend No." | i + 1 | endl; 15 15 yield(); 16 16 } 17 V(this ->lock);17 V(this.lock); 18 18 } 19 19 20 void main(Second *this) {21 P(this ->lock);20 void main(Second& this) { 21 P(this.lock); 22 22 for(int i = 0; i < 10; i++) { 23 23 sout | "Second : Suspend No." | i + 1 | endl; … … 33 33 processor p; 34 34 { 35 First f = { &lock };36 Second s = { &lock };35 First f = { lock }; 36 Second s = { lock }; 37 37 } 38 38 }
Note: See TracChangeset
for help on using the changeset viewer.