- Timestamp:
- Nov 2, 2017, 2:15:19 PM (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:
- 8fc45b7
- Parents:
- e1e8408
- Location:
- src/tests
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/boundedBuffer.c
re1e8408 r4cedd9f 1 // 1 // 2 2 // The contents of this file are covered under the licence agreement in the 3 3 // file "LICENCE" distributed with Cforall. 4 // 5 // boundedBuffer.c -- 6 // 4 // 5 // boundedBuffer.c -- 6 // 7 7 // Author : Peter A. Buhr 8 8 // Created On : Mon Oct 30 12:45:13 2017 … … 10 10 // Last Modified On : Mon Oct 30 18:00:10 2017 11 11 // Update Count : 7 12 // 12 // 13 13 14 14 #include <stdlib> … … 31 31 32 32 void insert( Buffer & mutex buffer, int elem ) { 33 if ( buffer.count == 20 ) wait( &buffer.empty );33 if ( buffer.count == 20 ) wait( buffer.empty ); 34 34 buffer.elements[buffer.back] = elem; 35 35 buffer.back = ( buffer.back + 1 ) % 20; 36 36 buffer.count += 1; 37 signal( &buffer.full );37 signal( buffer.full ); 38 38 } 39 39 int remove( Buffer & mutex buffer ) { 40 if ( buffer.count == 0 ) wait( &buffer.full );40 if ( buffer.count == 0 ) wait( buffer.full ); 41 41 int elem = buffer.elements[buffer.front]; 42 42 buffer.front = ( buffer.front + 1 ) % 20; 43 43 buffer.count -= 1; 44 signal( &buffer.empty );44 signal( buffer.empty ); 45 45 return elem; 46 46 } -
src/tests/datingService.c
re1e8408 r4cedd9f 1 // -*- Mode: C -*- 2 // 1 // -*- Mode: C -*- 2 // 3 3 // The contents of this file are covered under the licence agreement in the 4 4 // file "LICENCE" distributed with Cforall. 5 // 6 // datingService.c -- 7 // 5 // 6 // datingService.c -- 7 // 8 8 // Author : Peter A. Buhr 9 9 // Created On : Mon Oct 30 12:56:20 2017 … … 11 11 // Last Modified On : Mon Oct 30 17:58:41 2017 12 12 // Update Count : 14 13 // 13 // 14 14 15 15 #include <stdlib> // rand48 … … 18 18 #include <thread> 19 19 #include <unistd.h> // getpid 20 21 bool empty( condition & c ) {22 return c.blocked.head == NULL;23 }24 20 25 21 enum { NoOfPairs = 20 }; … … 31 27 32 28 unsigned int girl( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) { 33 if ( empty( ds.Boys[ccode] ) ) {34 wait( &ds.Girls[ccode] );29 if ( is_empty( ds.Boys[ccode] ) ) { 30 wait( ds.Girls[ccode] ); 35 31 ds.GirlPhoneNo = PhoneNo; 36 32 } else { 37 33 ds.GirlPhoneNo = PhoneNo; 38 signal_block( &ds.Boys[ccode] );34 signal_block( ds.Boys[ccode] ); 39 35 } // if 40 36 return ds.BoyPhoneNo; … … 42 38 43 39 unsigned int boy( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) { 44 if ( empty( ds.Girls[ccode] ) ) {45 wait( &ds.Boys[ccode] );40 if ( is_empty( ds.Girls[ccode] ) ) { 41 wait( ds.Boys[ccode] ); 46 42 ds.BoyPhoneNo = PhoneNo; 47 43 } else { 48 44 ds.BoyPhoneNo = PhoneNo; 49 signal_block( &ds.Girls[ccode] );45 signal_block( ds.Girls[ccode] ); 50 46 } // if 51 47 return ds.GirlPhoneNo; -
src/tests/sched-int-barge.c
re1e8408 r4cedd9f 73 73 if( action == c.do_wait1 || action == c.do_wait2 ) { 74 74 c.state = WAIT; 75 wait( &cond );75 wait( cond ); 76 76 77 77 if(c.state != SIGNAL) { … … 83 83 c.state = SIGNAL; 84 84 85 signal( &cond );86 signal( &cond );85 signal( cond ); 86 signal( cond ); 87 87 } 88 88 else { -
src/tests/sched-int-block.c
re1e8408 r4cedd9f 47 47 //------------------------------------------------------------------------------ 48 48 void wait_op( global_data_t & mutex a, global_data_t & mutex b, unsigned i ) { 49 wait( &cond, (uintptr_t)this_thread );49 wait( cond, (uintptr_t)this_thread ); 50 50 51 51 yield( rand48(10) ); … … 74 74 [a.last_thread, b.last_thread, a.last_signaller, b.last_signaller] = this_thread; 75 75 76 if( !is_empty( &cond ) ) {76 if( !is_empty( cond ) ) { 77 77 78 thread_desc * next = front( &cond );78 thread_desc * next = front( cond ); 79 79 80 if( ! signal_block( &cond ) ) {80 if( ! signal_block( cond ) ) { 81 81 sout | "ERROR expected to be able to signal" | endl; 82 82 abort(); -
src/tests/sched-int-disjoint.c
re1e8408 r4cedd9f 59 59 // Waiting logic 60 60 bool wait( global_t & mutex m, global_data_t & mutex d ) { 61 wait( &cond );61 wait( cond ); 62 62 if( d.state != SIGNAL ) { 63 63 sout | "ERROR barging!" | endl; … … 80 80 //------------------------------------------------------------------------------ 81 81 // Signalling logic 82 void signal( condition *cond, global_t & mutex a, global_data_t & mutex b ) {82 void signal( condition & cond, global_t & mutex a, global_data_t & mutex b ) { 83 83 b.state = SIGNAL; 84 84 signal( cond ); … … 86 86 87 87 void logic( global_t & mutex a ) { 88 signal( &cond, a, data );88 signal( cond, a, data ); 89 89 90 90 yield( rand48(10) ); -
src/tests/sched-int-wait.c
re1e8408 r4cedd9f 41 41 //---------------------------------------------------------------------------------------------------- 42 42 // Tools 43 void signal( condition *cond, global_t & mutex a, global_t & mutex b ) {43 void signal( condition & cond, global_t & mutex a, global_t & mutex b ) { 44 44 signal( cond ); 45 45 } 46 46 47 void signal( condition *cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) {47 void signal( condition & cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 48 48 signal( cond ); 49 49 } 50 50 51 void wait( condition *cond, global_t & mutex a, global_t & mutex b ) {51 void wait( condition & cond, global_t & mutex a, global_t & mutex b ) { 52 52 wait( cond ); 53 53 } 54 54 55 void wait( condition *cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) {55 void wait( condition & cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 56 56 wait( cond ); 57 57 } … … 65 65 switch( action ) { 66 66 case 0: 67 signal( &condABC, globalA, globalB, globalC );67 signal( condABC, globalA, globalB, globalC ); 68 68 break; 69 69 case 1: 70 signal( &condAB , globalA, globalB );70 signal( condAB , globalA, globalB ); 71 71 break; 72 72 case 2: 73 signal( &condBC , globalB, globalC );73 signal( condBC , globalB, globalC ); 74 74 break; 75 75 case 3: 76 signal( &condAC , globalA, globalC );76 signal( condAC , globalA, globalC ); 77 77 break; 78 78 default: … … 88 88 void main( WaiterABC & this ) { 89 89 for( int i = 0; i < N; i++ ) { 90 wait( &condABC, globalA, globalB, globalC );90 wait( condABC, globalA, globalB, globalC ); 91 91 } 92 92 … … 98 98 void main( WaiterAB & this ) { 99 99 for( int i = 0; i < N; i++ ) { 100 wait( &condAB , globalA, globalB );100 wait( condAB , globalA, globalB ); 101 101 } 102 102 … … 108 108 void main( WaiterAC & this ) { 109 109 for( int i = 0; i < N; i++ ) { 110 wait( &condAC , globalA, globalC );110 wait( condAC , globalA, globalC ); 111 111 } 112 112 … … 118 118 void main( WaiterBC & this ) { 119 119 for( int i = 0; i < N; i++ ) { 120 wait( &condBC , globalB, globalC );120 wait( condBC , globalB, globalC ); 121 121 } 122 122 -
src/tests/thread.c
re1e8408 r4cedd9f 15 15 yield(); 16 16 } 17 V( this.lock);17 V(*this.lock); 18 18 } 19 19 20 20 void main(Second& this) { 21 P( this.lock);21 P(*this.lock); 22 22 for(int i = 0; i < 10; i++) { 23 23 sout | "Second : Suspend No." | i + 1 | endl;
Note:
See TracChangeset
for help on using the changeset viewer.