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