Changes in src/tests/sched-int-disjoint.c [cd99ef1:83a071f9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/sched-int-disjoint.c
rcd99ef1 r83a071f9 4 4 #include <thread> 5 5 6 static const unsigned long N = 10_000ul; 7 8 #ifndef PREEMPTION_RATE 9 #define PREEMPTION_RATE 10_000ul 6 #ifndef N 7 #define N 10_000 10 8 #endif 11 12 unsigned int default_preemption() {13 return PREEMPTION_RATE;14 }15 9 16 10 enum state_t { WAIT, SIGNAL, BARGE }; … … 20 14 21 15 monitor global_data_t; 22 void ?{}( global_data_t *this );23 void ^?{} ( global_data_t *this );16 void ?{}( global_data_t & this ); 17 void ^?{} ( global_data_t & this ); 24 18 25 19 monitor global_data_t { … … 32 26 volatile bool all_done; 33 27 34 void ?{}( global_data_t *this ) {35 this ->counter == 0;36 this ->state = BARGE;28 void ?{}( global_data_t & this ) { 29 this.counter == 0; 30 this.state = BARGE; 37 31 } 38 32 39 void ^?{} ( global_data_t *this ) {}33 void ^?{} ( global_data_t & this ) {} 40 34 41 35 //------------------------------------------------------------------------------ 42 36 // Barging logic 43 void barge( global_data_t *mutex d ) {44 d ->state = BARGE;37 void barge( global_data_t & mutex d ) { 38 d.state = BARGE; 45 39 } 46 40 47 41 thread Barger {}; 48 42 49 void main( Barger *this ) {43 void main( Barger & this ) { 50 44 while( !all_done ) { 51 barge( &data );45 barge( data ); 52 46 yield(); 53 47 } … … 56 50 //------------------------------------------------------------------------------ 57 51 // Waiting logic 58 bool wait( global_t * mutex m, global_data_t *mutex d ) {52 bool wait( global_t & mutex m, global_data_t & mutex d ) { 59 53 wait( &cond ); 60 if( d ->state != SIGNAL ) {54 if( d.state != SIGNAL ) { 61 55 sout | "ERROR barging!" | endl; 62 56 } 63 57 64 d ->counter++;58 d.counter++; 65 59 66 if( (d ->counter % 1000) == 0 ) sout | d->counter | endl;60 if( (d.counter % 1000) == 0 ) sout | d.counter | endl; 67 61 68 return d ->counter < N;62 return d.counter < N; 69 63 } 70 64 71 65 thread Waiter {}; 72 66 73 void main( Waiter *this ) {74 while( wait( &mut, &data ) ) { yield(); }67 void main( Waiter & this ) { 68 while( wait( mut, data ) ) { yield(); } 75 69 } 76 70 … … 78 72 //------------------------------------------------------------------------------ 79 73 // Signalling logic 80 void signal( condition * cond, global_t * mutex a, global_data_t *mutex b ) {81 b ->state = SIGNAL;74 void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) { 75 b.state = SIGNAL; 82 76 signal( cond ); 83 77 } 84 78 85 void logic( global_t *mutex a ) {86 signal( &cond, a, &data );79 void logic( global_t & mutex a ) { 80 signal( &cond, a, data ); 87 81 88 82 yield( (unsigned)rand48() % 10 ); … … 97 91 thread Signaller {}; 98 92 99 void main( Signaller *this ) {93 void main( Signaller & this ) { 100 94 while( !all_done ) { 101 logic( &mut );95 logic( mut ); 102 96 yield(); 103 97 }
Note:
See TracChangeset
for help on using the changeset viewer.