Ignore:
File:
1 edited

Legend:

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

    r83a071f9 r303406a  
    44#include <thread>
    55
    6 #ifndef N
    7 #define N 10_000
     6#include <time.h>
     7
     8static const unsigned long N = 10_000ul;
     9
     10#ifndef PREEMPTION_RATE
     11#define PREEMPTION_RATE 10_000ul
    812#endif
     13
     14unsigned int default_preemption() {
     15        return PREEMPTION_RATE;
     16}
    917
    1018enum state_t { WAIT, SIGNAL, BARGE };
     
    1422
    1523monitor global_data_t;
    16 void ?{}( global_data_t & this );
    17 void ^?{} ( global_data_t & this );
     24void ?{}( global_data_t * this );
     25void ^?{} ( global_data_t * this );
    1826
    1927monitor global_data_t {
     
    2634volatile bool all_done;
    2735
    28 void ?{}( global_data_t & this ) {
    29         this.counter == 0;
    30         this.state = BARGE;
     36void ?{}( global_data_t * this ) {
     37        this->counter == 0;
     38        this->state = BARGE;
    3139}
    3240
    33 void ^?{} ( global_data_t & this ) {}
     41void ^?{} ( global_data_t * this ) {}
    3442
    3543//------------------------------------------------------------------------------
    3644// Barging logic
    37 void barge( global_data_t & mutex d ) {
    38         d.state = BARGE;
     45void barge( global_data_t * mutex d ) {
     46        d->state = BARGE;
    3947}
    4048
    4149thread Barger {};
    4250
    43 void main( Barger & this ) {
     51void main( Barger * this ) {
    4452        while( !all_done ) {
    45                 barge( data );
     53                barge( &data );
    4654                yield();
    4755        }
     
    5058//------------------------------------------------------------------------------
    5159// Waiting logic
    52 bool wait( global_t & mutex m, global_data_t & mutex d ) {
     60bool wait( global_t * mutex m, global_data_t * mutex d ) {
    5361        wait( &cond );
    54         if( d.state != SIGNAL ) {
     62        if( d->state != SIGNAL ) {
    5563                sout | "ERROR barging!" | endl;
    5664        }
    5765
    58         d.counter++;
     66        d->counter++;
    5967
    60         if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
     68        if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
    6169
    62         return d.counter < N;
     70        return d->counter < N;
    6371}
    6472
    6573thread Waiter {};
    6674
    67 void main( Waiter & this ) {
    68         while( wait( mut, data ) ) { yield(); }
     75void main( Waiter * this ) {
     76        while( wait( &mut, &data ) ) { yield(); }
    6977}
    7078
     
    7280//------------------------------------------------------------------------------
    7381// Signalling logic
    74 void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) {
    75         b.state = SIGNAL;
     82void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
     83        b->state = SIGNAL;
    7684        signal( cond );
    7785}
    7886
    79 void logic( global_t & mutex a ) {
    80         signal( &cond, a, data );
     87void logic( global_t * mutex a ) {
     88        signal( &cond, a, &data );
    8189
    8290        yield( (unsigned)rand48() % 10 );
     
    9199thread Signaller {};
    92100
    93 void main( Signaller & this ) {
     101void main( Signaller * this ) {
    94102        while( !all_done ) {
    95                 logic( mut );
     103                logic( &mut );
    96104                yield();
    97105        }
     
    101109// Main loop
    102110int main(int argc, char* argv[]) {
     111        rand48seed( time( NULL ) );
    103112        all_done = false;
    104113        processor p;
Note: See TracChangeset for help on using the changeset viewer.