Ignore:
File:
1 edited

Legend:

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

    rcd99ef1 r83a071f9  
    44#include <thread>
    55
    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
    108#endif
    11 
    12 unsigned int default_preemption() {
    13         return PREEMPTION_RATE;
    14 }
    159
    1610enum state_t { WAIT, SIGNAL, BARGE };
     
    2014
    2115monitor global_data_t;
    22 void ?{}( global_data_t * this );
    23 void ^?{} ( global_data_t * this );
     16void ?{}( global_data_t & this );
     17void ^?{} ( global_data_t & this );
    2418
    2519monitor global_data_t {
     
    3226volatile bool all_done;
    3327
    34 void ?{}( global_data_t * this ) {
    35         this->counter == 0;
    36         this->state = BARGE;
     28void ?{}( global_data_t & this ) {
     29        this.counter == 0;
     30        this.state = BARGE;
    3731}
    3832
    39 void ^?{} ( global_data_t * this ) {}
     33void ^?{} ( global_data_t & this ) {}
    4034
    4135//------------------------------------------------------------------------------
    4236// Barging logic
    43 void barge( global_data_t * mutex d ) {
    44         d->state = BARGE;
     37void barge( global_data_t & mutex d ) {
     38        d.state = BARGE;
    4539}
    4640
    4741thread Barger {};
    4842
    49 void main( Barger * this ) {
     43void main( Barger & this ) {
    5044        while( !all_done ) {
    51                 barge( &data );
     45                barge( data );
    5246                yield();
    5347        }
     
    5650//------------------------------------------------------------------------------
    5751// Waiting logic
    58 bool wait( global_t * mutex m, global_data_t * mutex d ) {
     52bool wait( global_t & mutex m, global_data_t & mutex d ) {
    5953        wait( &cond );
    60         if( d->state != SIGNAL ) {
     54        if( d.state != SIGNAL ) {
    6155                sout | "ERROR barging!" | endl;
    6256        }
    6357
    64         d->counter++;
     58        d.counter++;
    6559
    66         if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
     60        if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
    6761
    68         return d->counter < N;
     62        return d.counter < N;
    6963}
    7064
    7165thread Waiter {};
    7266
    73 void main( Waiter * this ) {
    74         while( wait( &mut, &data ) ) { yield(); }
     67void main( Waiter & this ) {
     68        while( wait( mut, data ) ) { yield(); }
    7569}
    7670
     
    7872//------------------------------------------------------------------------------
    7973// Signalling logic
    80 void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
    81         b->state = SIGNAL;
     74void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) {
     75        b.state = SIGNAL;
    8276        signal( cond );
    8377}
    8478
    85 void logic( global_t * mutex a ) {
    86         signal( &cond, a, &data );
     79void logic( global_t & mutex a ) {
     80        signal( &cond, a, data );
    8781
    8882        yield( (unsigned)rand48() % 10 );
     
    9791thread Signaller {};
    9892
    99 void main( Signaller * this ) {
     93void main( Signaller & this ) {
    10094        while( !all_done ) {
    101                 logic( &mut );
     95                logic( mut );
    10296                yield();
    10397        }
Note: See TracChangeset for help on using the changeset viewer.