Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/sched-int-disjoint.c

    r303406a r83a071f9  
    44#include <thread>
    55
    6 #include <time.h>
    7 
    8 static const unsigned long N = 10_000ul;
    9 
    10 #ifndef PREEMPTION_RATE
    11 #define PREEMPTION_RATE 10_000ul
     6#ifndef N
     7#define N 10_000
    128#endif
    13 
    14 unsigned int default_preemption() {
    15         return PREEMPTION_RATE;
    16 }
    179
    1810enum state_t { WAIT, SIGNAL, BARGE };
     
    2214
    2315monitor global_data_t;
    24 void ?{}( global_data_t * this );
    25 void ^?{} ( global_data_t * this );
     16void ?{}( global_data_t & this );
     17void ^?{} ( global_data_t & this );
    2618
    2719monitor global_data_t {
     
    3426volatile bool all_done;
    3527
    36 void ?{}( global_data_t * this ) {
    37         this->counter == 0;
    38         this->state = BARGE;
     28void ?{}( global_data_t & this ) {
     29        this.counter == 0;
     30        this.state = BARGE;
    3931}
    4032
    41 void ^?{} ( global_data_t * this ) {}
     33void ^?{} ( global_data_t & this ) {}
    4234
    4335//------------------------------------------------------------------------------
    4436// Barging logic
    45 void barge( global_data_t * mutex d ) {
    46         d->state = BARGE;
     37void barge( global_data_t & mutex d ) {
     38        d.state = BARGE;
    4739}
    4840
    4941thread Barger {};
    5042
    51 void main( Barger * this ) {
     43void main( Barger & this ) {
    5244        while( !all_done ) {
    53                 barge( &data );
     45                barge( data );
    5446                yield();
    5547        }
     
    5850//------------------------------------------------------------------------------
    5951// Waiting logic
    60 bool wait( global_t * mutex m, global_data_t * mutex d ) {
     52bool wait( global_t & mutex m, global_data_t & mutex d ) {
    6153        wait( &cond );
    62         if( d->state != SIGNAL ) {
     54        if( d.state != SIGNAL ) {
    6355                sout | "ERROR barging!" | endl;
    6456        }
    6557
    66         d->counter++;
     58        d.counter++;
    6759
    68         if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
     60        if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
    6961
    70         return d->counter < N;
     62        return d.counter < N;
    7163}
    7264
    7365thread Waiter {};
    7466
    75 void main( Waiter * this ) {
    76         while( wait( &mut, &data ) ) { yield(); }
     67void main( Waiter & this ) {
     68        while( wait( mut, data ) ) { yield(); }
    7769}
    7870
     
    8072//------------------------------------------------------------------------------
    8173// Signalling logic
    82 void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
    83         b->state = SIGNAL;
     74void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) {
     75        b.state = SIGNAL;
    8476        signal( cond );
    8577}
    8678
    87 void logic( global_t * mutex a ) {
    88         signal( &cond, a, &data );
     79void logic( global_t & mutex a ) {
     80        signal( &cond, a, data );
    8981
    9082        yield( (unsigned)rand48() % 10 );
     
    9991thread Signaller {};
    10092
    101 void main( Signaller * this ) {
     93void main( Signaller & this ) {
    10294        while( !all_done ) {
    103                 logic( &mut );
     95                logic( mut );
    10496                yield();
    10597        }
     
    109101// Main loop
    110102int main(int argc, char* argv[]) {
    111         rand48seed( time( NULL ) );
    112103        all_done = false;
    113104        processor p;
Note: See TracChangeset for help on using the changeset viewer.