Ignore:
File:
1 edited

Legend:

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

    r83a071f9 rcd99ef1  
    44#include <thread>
    55
    6 #ifndef N
    7 #define N 10_000
     6static const unsigned long N = 10_000ul;
     7
     8#ifndef PREEMPTION_RATE
     9#define PREEMPTION_RATE 10_000ul
    810#endif
     11
     12unsigned int default_preemption() {
     13        return PREEMPTION_RATE;
     14}
    915
    1016enum state_t { WAIT, SIGNAL, BARGE };
     
    1420
    1521monitor global_data_t;
    16 void ?{}( global_data_t & this );
    17 void ^?{} ( global_data_t & this );
     22void ?{}( global_data_t * this );
     23void ^?{} ( global_data_t * this );
    1824
    1925monitor global_data_t {
     
    2632volatile bool all_done;
    2733
    28 void ?{}( global_data_t & this ) {
    29         this.counter == 0;
    30         this.state = BARGE;
     34void ?{}( global_data_t * this ) {
     35        this->counter == 0;
     36        this->state = BARGE;
    3137}
    3238
    33 void ^?{} ( global_data_t & this ) {}
     39void ^?{} ( global_data_t * this ) {}
    3440
    3541//------------------------------------------------------------------------------
    3642// Barging logic
    37 void barge( global_data_t & mutex d ) {
    38         d.state = BARGE;
     43void barge( global_data_t * mutex d ) {
     44        d->state = BARGE;
    3945}
    4046
    4147thread Barger {};
    4248
    43 void main( Barger & this ) {
     49void main( Barger * this ) {
    4450        while( !all_done ) {
    45                 barge( data );
     51                barge( &data );
    4652                yield();
    4753        }
     
    5056//------------------------------------------------------------------------------
    5157// Waiting logic
    52 bool wait( global_t & mutex m, global_data_t & mutex d ) {
     58bool wait( global_t * mutex m, global_data_t * mutex d ) {
    5359        wait( &cond );
    54         if( d.state != SIGNAL ) {
     60        if( d->state != SIGNAL ) {
    5561                sout | "ERROR barging!" | endl;
    5662        }
    5763
    58         d.counter++;
     64        d->counter++;
    5965
    60         if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
     66        if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
    6167
    62         return d.counter < N;
     68        return d->counter < N;
    6369}
    6470
    6571thread Waiter {};
    6672
    67 void main( Waiter & this ) {
    68         while( wait( mut, data ) ) { yield(); }
     73void main( Waiter * this ) {
     74        while( wait( &mut, &data ) ) { yield(); }
    6975}
    7076
     
    7278//------------------------------------------------------------------------------
    7379// Signalling logic
    74 void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) {
    75         b.state = SIGNAL;
     80void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
     81        b->state = SIGNAL;
    7682        signal( cond );
    7783}
    7884
    79 void logic( global_t & mutex a ) {
    80         signal( &cond, a, data );
     85void logic( global_t * mutex a ) {
     86        signal( &cond, a, &data );
    8187
    8288        yield( (unsigned)rand48() % 10 );
     
    9197thread Signaller {};
    9298
    93 void main( Signaller & this ) {
     99void main( Signaller * this ) {
    94100        while( !all_done ) {
    95                 logic( mut );
     101                logic( &mut );
    96102                yield();
    97103        }
Note: See TracChangeset for help on using the changeset viewer.