Changeset 83a071f9


Ignore:
Timestamp:
Aug 11, 2017, 10:10:26 AM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
fd344aa
Parents:
8499c707
Message:

Fix concurrency library, tests, and keywords for references

Location:
src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r8499c707 r83a071f9  
    291291                        LinkageSpec::Cforall,
    292292                        nullptr,
    293                         new PointerType(
     293                        new ReferenceType(
    294294                                noQualifiers,
    295295                                new StructInstType(
     
    447447
    448448                //Makes sure it's not a copy
    449                 PointerType* pty = dynamic_cast< PointerType * >( ty );
    450449                ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
    451                 if( ! pty && ! rty ) throw SemanticError( "Mutex argument must be of pointer/reference type ", arg );
     450                if( ! rty ) throw SemanticError( "Mutex argument must be of reference type ", arg );
    452451
    453452                //Make sure the we are pointing directly to a type
    454                 Type* base = pty ? pty->get_base() : rty->get_base();
    455                 if(  dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
     453                Type* base = rty->get_base();
     454                if( dynamic_cast< ReferenceType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
     455                if( dynamic_cast< PointerType * >( base ) ) throw SemanticError( "Mutex argument have exactly one level of indirection ", arg );
    456456
    457457                //Make sure that typed isn't mutex
  • src/libcfa/concurrency/coroutine

    r8499c707 r83a071f9  
    2626// Anything that is resumed is a coroutine.
    2727trait is_coroutine(dtype T) {
    28       void main(T * this);
    29       coroutine_desc * get_coroutine(T * this);
     28      void main(T & this);
     29      coroutine_desc * get_coroutine(T & this);
    3030};
    3131
    32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this)
     32#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this)
    3333
    3434//-----------------------------------------------------------------------------
     
    4545
    4646forall(dtype T | is_coroutine(T))
    47 static inline void resume(T * cor);
     47static inline void resume(T & cor);
    4848
    4949forall(dtype T | is_coroutine(T))
    50 void prime(T * cor);
     50void prime(T & cor);
    5151
    5252//-----------------------------------------------------------------------------
     
    8787// Resume implementation inlined for performance
    8888forall(dtype T | is_coroutine(T))
    89 static inline void resume(T * cor) {
     89static inline void resume(T & cor) {
    9090        coroutine_desc * src = this_coroutine;          // optimization
    9191        coroutine_desc * dst = get_coroutine(cor);
     
    9393        if( unlikely(!dst->stack.base) ) {
    9494                create_stack(&dst->stack, dst->stack.size);
    95                 CtxStart(cor, CtxInvokeCoroutine);
     95                CtxStart(&cor, CtxInvokeCoroutine);
    9696        }
    9797
  • src/libcfa/concurrency/coroutine.c

    r8499c707 r83a071f9  
    9393// Not inline since only ever called once per coroutine
    9494forall(dtype T | is_coroutine(T))
    95 void prime(T* cor) {
     95void prime(T& cor) {
    9696        coroutine_desc* this = get_coroutine(cor);
    9797        assert(this->state == Start);
  • src/libcfa/concurrency/kernel.c

    r8499c707 r83a071f9  
    139139}
    140140
    141 void ?{}(processor & this, cluster * cltr, processorCtx_t * runner) {
     141void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) {
    142142        this.cltr = cltr;
    143143        (this.terminated){ 0 };
     
    148148        this.kernel_thread = pthread_self();
    149149
    150         this.runner = runner;
    151         LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", runner);
    152         (*runner){ &this };
     150        this.runner = &runner;
     151        LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", &runner);
     152        runner{ &this };
    153153}
    154154
    155155LIB_DEBUG_DO( bool validate( alarm_list_t * this ); )
    156156
    157 void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t * runner) {
     157void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t & runner) {
    158158        (this.alarms){};
    159159        (this.alarm_lock){};
     
    187187//=============================================================================================
    188188//Main of the processor contexts
    189 void main(processorCtx_t * runner) {
    190         processor * this = runner->proc;
     189void main(processorCtx_t & runner) {
     190        processor * this = runner.proc;
    191191
    192192        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     
    233233// from the processor coroutine to the target thread
    234234void runThread(processor * this, thread_desc * dst) {
    235         coroutine_desc * proc_cor = get_coroutine(this->runner);
     235        coroutine_desc * proc_cor = get_coroutine(*this->runner);
    236236        coroutine_desc * thrd_cor = get_coroutine(dst);
    237237
     
    315315        // appropriate stack.
    316316        proc_cor_storage.__cor.state = Active;
    317         main( &proc_cor_storage );
     317        main( proc_cor_storage );
    318318        proc_cor_storage.__cor.state = Halted;
    319319
     
    455455        mainThread = (thread_desc *)&mainThreadStorage;
    456456        current_stack_info_t info;
    457         mainThread{ &info };
     457        (*mainThread){ &info };
    458458
    459459        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     
    461461        // Initialize the system cluster
    462462        systemCluster = (cluster *)&systemClusterStorage;
    463         systemCluster{};
     463        (*systemCluster){};
    464464
    465465        LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n");
     
    468468        // (the coroutine that contains the processing control flow)
    469469        systemProcessor = (system_proc_t *)&systemProcessorStorage;
    470         (*systemProcessor){ systemCluster, (processorCtx_t *)&systemProcessorCtxStorage };
     470        (*systemProcessor){ systemCluster, *(processorCtx_t *)&systemProcessorCtxStorage };
    471471
    472472        // Add the main thread to the ready queue
     
    486486        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    487487        // mainThread is on the ready queue when this call is made.
    488         resume( systemProcessor->proc.runner );
     488        resume( *systemProcessor->proc.runner );
    489489
    490490
     
    514514        // Destroy the system processor and its context in reverse order of construction
    515515        // These were manually constructed so we need manually destroy them
    516         ^(systemProcessor->proc.runner){};
     516        ^(*systemProcessor->proc.runner){};
    517517        ^(systemProcessor){};
    518518
  • src/libcfa/concurrency/thread

    r8499c707 r83a071f9  
    3030trait is_thread(dtype T) {
    3131      void ^?{}(T& mutex this);
    32       void main(T* this);
    33       thread_desc* get_thread(T* this);
     32      void main(T& this);
     33      thread_desc* get_thread(T& this);
    3434};
    3535
    36 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
     36#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
    3737
    3838forall( dtype T | is_thread(T) )
    39 static inline coroutine_desc* get_coroutine(T* this) {
     39static inline coroutine_desc* get_coroutine(T & this) {
    4040        return &get_thread(this)->cor;
    4141}
    4242
    4343forall( dtype T | is_thread(T) )
    44 static inline monitor_desc* get_monitor(T * this) {
     44static inline monitor_desc* get_monitor(T & this) {
    4545        return &get_thread(this)->mon;
    4646}
     
    5757
    5858forall( dtype T | is_thread(T) )
    59 void __thrd_start( T* this );
     59void __thrd_start( T & this );
    6060
    6161//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/thread.c

    r8499c707 r83a071f9  
    5151void ?{}( scoped(T)& this ) {
    5252        (this.handle){};
    53         __thrd_start(&this.handle);
     53        __thrd_start(this.handle);
    5454}
    5555
     
    5757void ?{}( scoped(T)& this, P params ) {
    5858        (this.handle){ params };
    59         __thrd_start(&this.handle);
     59        __thrd_start(this.handle);
    6060}
    6161
     
    6868// Starting and stopping threads
    6969forall( dtype T | is_thread(T) )
    70 void __thrd_start( T* this ) {
     70void __thrd_start( T& this ) {
    7171        coroutine_desc* thrd_c = get_coroutine(this);
    7272        thread_desc*  thrd_h = get_thread   (this);
     
    7878        create_stack(&thrd_c->stack, thrd_c->stack.size);
    7979        this_coroutine = thrd_c;
    80         CtxStart(this, CtxInvokeThread);
     80        CtxStart(&this, CtxInvokeThread);
    8181        assert( thrd_c->last->stack.context );
    8282        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
  • src/libcfa/stdlib

    r8499c707 r83a071f9  
    135135// allocation/deallocation and constructor/destructor, non-array types
    136136forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );
    137 forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr );
    138 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
     137forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );
     138forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    139139
    140140// allocation/deallocation and constructor/destructor, array types
  • src/libcfa/stdlib.c

    r8499c707 r83a071f9  
    4444} // new
    4545
    46 forall( dtype T | { void ^?{}( T & ); } )
     46forall( dtype T | sized(T) | { void ^?{}( T & ); } )
    4747void delete( T * ptr ) {
    4848        if ( ptr ) {                                                                            // ignore null
    49                 ^ptr{};                                                                                 // run destructor
     49                ^(*ptr){};                                                                                      // run destructor
    5050                free( ptr );
    5151        } // if
    5252} // delete
    5353
    54 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } )
     54forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    5555void delete( T * ptr, Params rest ) {
    5656        if ( ptr ) {                                                                            // ignore null
    57                 ^ptr{};                                                                                 // run destructor
     57                ^(*ptr){};                                                                                      // run destructor
    5858                free( ptr );
    5959        } // if
  • src/tests/coroutine.c

    r8499c707 r83a071f9  
    2525}
    2626
    27 void main( Fibonacci * this ) {
     27void main( Fibonacci & this ) {
    2828        int fn1, fn2;                                   // retained between resumes
    29         this->fn = 0;                                   // case 0
    30         fn1 = this->fn;
     29        this.fn = 0;                                    // case 0
     30        fn1 = this.fn;
    3131        suspend();                                              // return to last resume
    3232
    33         this->fn = 1;                                   // case 1
     33        this.fn = 1;                                    // case 1
    3434        fn2 = fn1;
    35         fn1 = this->fn;
     35        fn1 = this.fn;
    3636        suspend();                                              // return to last resume
    3737
    3838        for ( ;; ) {                                    // general case
    39                 this->fn = fn1 + fn2;
     39                this.fn = fn1 + fn2;
    4040                fn2 = fn1;
    41                 fn1 = this->fn;
     41                fn1 = this.fn;
    4242                suspend();                                      // return to last resume
    4343        } // for
    4444}
    4545
    46 int next( Fibonacci * this ) {
     46int next( Fibonacci & this ) {
    4747        resume( this );                                 // transfer to last suspend
    48         return this->fn;
     48        return this.fn;
    4949}
    5050
     
    5252        Fibonacci f1, f2;
    5353        for ( int i = 1; i <= 10; i += 1 ) {
    54                 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
     54                sout | next( f1 ) | ' ' | next( f2 ) | endl;
    5555        } // for
    5656}
  • src/tests/monitor.c

    r8499c707 r83a071f9  
    1414static global_t global;
    1515
    16 void increment3( global_t * mutex this ) {
    17         this->value += 1;
     16void increment3( global_t & mutex this ) {
     17        this.value += 1;
    1818}
    1919
    20 void increment2( global_t * mutex this ) {
     20void increment2( global_t & mutex this ) {
    2121        increment3( this );
    2222}
    2323
    24 void increment( global_t * mutex this ) {
     24void increment( global_t & mutex this ) {
    2525        increment2( this );
    2626}
     
    2828thread MyThread {};
    2929
    30 void main( MyThread* this ) {
     30void main( MyThread & this ) {
    3131        for(int i = 0; i < 1_000_000; i++) {
    32                 increment( &global );
     32                increment( global );
    3333        }
    3434}
  • src/tests/multi-monitor.c

    r8499c707 r83a071f9  
    1010static monitor_t m1, m2, m3;
    1111
    12 void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) {
    13         *value += 1;
     12void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) {
     13        value += 1;
    1414}
    1515
    16 struct MyThread {
    17         thread_desc __thrd;
     16thread MyThread {
    1817        int target;
    1918};
    20 
    21 DECL_THREAD(MyThread);
    2219
    2320void ?{}( MyThread & this, int target ) {
     
    2724void ^?{}( MyThread & mutex this ) {}
    2825
    29 void main( MyThread* this ) {
     26void main( MyThread & this ) {
    3027        for(int i = 0; i < 1000000; i++) {
    31                 choose(this->target) {
    32                         case 0: increment( &m1, &m2, &global12 );
    33                         case 1: increment( &m2, &m3, &global23 );
    34                         case 2: increment( &m1, &m3, &global13 );
     28                choose(this.target) {
     29                        case 0: increment( m1, m2, global12 );
     30                        case 1: increment( m2, m3, global23 );
     31                        case 2: increment( m1, m3, global13 );
    3532                }
    3633        }
     34}
     35
     36forall(dtype T | sized(T) | { void ^?{}(T & mutex); })
     37void delete_mutex(T * x) {
     38        ^(*x){};
     39        free(x);
    3740}
    3841
     
    4043        processor p;
    4144        {
    42                 scoped(MyThread) * f[6];
     45                MyThread * f[6];
    4346                for(int i = 0; i < 6; i++) {
    44                         f[i] = (*(scoped(MyThread) *)malloc()){ i % 3 };
     47                        f[i] = new(i % 3);
    4548                }
    4649
    4750                for(int i = 0; i < 6; i++) {
    48                         delete( f[i] );
     51                        delete_mutex( f[i] );
    4952                }
    5053        }
  • src/tests/preempt.c

    r8499c707 r83a071f9  
    2020}
    2121
    22 void main(worker_t * this) {
     22void main(worker_t & this) {
    2323        while(counter < 1000) {
    24                 if( (counter % 7) == this->value ) {
     24                if( (counter % 7) == this.value ) {
    2525                        int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST);
    2626                        if( (next % 100) == 0 ) printf("%d\n", next);
  • src/tests/sched-int-barge.c

    r8499c707 r83a071f9  
    3939thread Threads {};
    4040
    41 bool logicC( global_t * mutex a, global_t * mutex b, global_data_t * mutex c ) {
    42         c->counter++;
     41bool logicC( global_t & mutex a, global_t & mutex b, global_data_t & mutex c ) {
     42        c.counter++;
    4343
    44         if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
     44        if( (c.counter % 1000) == 0 ) sout | c.counter | endl;
    4545
    46         int action = c->counter % 10;
     46        int action = c.counter % 10;
    4747
    4848        if( action == 0 ) {
    49                 c->do_signal = max( ((unsigned)rand48()) % 10, 1);
    50                 c->do_wait1 = ((unsigned)rand48()) % (c->do_signal);
    51                 c->do_wait2 = ((unsigned)rand48()) % (c->do_signal);
     49                c.do_signal = max( ((unsigned)rand48()) % 10, 1);
     50                c.do_wait1 = ((unsigned)rand48()) % (c.do_signal);
     51                c.do_wait2 = ((unsigned)rand48()) % (c.do_signal);
    5252
    53                 // if(c->do_wait1 == c->do_wait2) sout | "Same" | endl;
     53                // if(c.do_wait1 == c.do_wait2) sout | "Same" | endl;
    5454        }
    5555
    56         if( action == c->do_wait1 || action == c->do_wait2 ) {
    57                 c->state = WAIT;
     56        if( action == c.do_wait1 || action == c.do_wait2 ) {
     57                c.state = WAIT;
    5858                wait( &cond );
    5959
    60                 if(c->state != SIGNAL) {
    61                         sout | "ERROR Barging detected" | c->counter | endl;
     60                if(c.state != SIGNAL) {
     61                        sout | "ERROR Barging detected" | c.counter | endl;
    6262                        abort();
    6363                }
    6464        }
    65         else if( action == c->do_signal ) {
    66                 c->state = SIGNAL;
     65        else if( action == c.do_signal ) {
     66                c.state = SIGNAL;
    6767
    6868                signal( &cond );
     
    7070        }
    7171        else {
    72                 c->state = BARGE;
     72                c.state = BARGE;
    7373        }
    7474
    75         if( c->counter >= 100_000 ) c->done = true;
    76         return !c->done;
     75        if( c.counter >= 100_000 ) c.done = true;
     76        return !c.done;
    7777}
    7878
    79 bool logicB( global_t * mutex a, global_t * mutex b ) {
    80         return logicC(a, b, &globalC);
     79bool logicB( global_t & mutex a, global_t & mutex b ) {
     80        return logicC(a, b, globalC);
    8181}
    8282
    83 bool logicA( global_t * mutex a ) {
    84         return logicB(a, &globalB);
     83bool logicA( global_t & mutex a ) {
     84        return logicB(a, globalB);
    8585}
    8686
    87 void main( Threads* this ) {
    88         while( logicA(&globalA) ) { yield(); };
     87void main( Threads & this ) {
     88        while( logicA(globalA) ) { yield(); };
    8989}
    9090
  • src/tests/sched-int-block.c

    r8499c707 r83a071f9  
    3030
    3131//------------------------------------------------------------------------------
    32 void wait_op( global_data_t * mutex a, global_data_t * mutex b, unsigned i ) {
     32void wait_op( global_data_t & mutex a, global_data_t & mutex b, unsigned i ) {
    3333        wait( &cond, (uintptr_t)this_thread );
    3434
    3535        yield( ((unsigned)rand48()) % 10 );
    3636
    37         if(a->last_thread != a->last_signaller || b->last_thread != b->last_signaller ) {
    38                 sout | "ERROR Barging detected, expected" | a->last_signaller | b->last_signaller | "got" | a->last_thread | b->last_thread | endl;
     37        if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) {
     38                sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl;
    3939                abort();
    4040        }
    4141
    42         a->last_thread = b->last_thread = this_thread;
     42        a.last_thread = b.last_thread = this_thread;
    4343
    4444        yield( ((unsigned)rand48()) % 10 );
     
    4646
    4747thread Waiter {};
    48 void main( Waiter* this ) {
     48void main( Waiter & this ) {
    4949        for( int i = 0; i < N; i++ ) {
    50                 wait_op( &globalA, &globalB, i );
     50                wait_op( globalA, globalB, i );
    5151        }
    5252}
    5353
    5454//------------------------------------------------------------------------------
    55 void signal_op( global_data_t * mutex a, global_data_t * mutex b ) {
     55void signal_op( global_data_t & mutex a, global_data_t & mutex b ) {
    5656        yield( ((unsigned)rand48()) % 10 );
    5757
    58         a->last_thread = b->last_thread = a->last_signaller = b->last_signaller = this_thread;
     58        [a.last_thread, b.last_thread, a.last_signaller, b.last_signaller] = this_thread;
    5959
    6060        if( !is_empty( &cond ) ) {
     
    6969                yield( ((unsigned)rand48()) % 10 );
    7070
    71                 if(a->last_thread != next || b->last_thread != next) {
    72                         sout | "ERROR Barging detected, expected" | next | "got" | a->last_thread | b->last_thread | endl;
     71                if(a.last_thread != next || b.last_thread != next) {
     72                        sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl;
    7373                        abort();
    7474                }
     
    7878
    7979thread Signaller {};
    80 void main( Signaller* this ) {
     80void main( Signaller & this ) {
    8181        while( !done ) {
    82                 signal_op( &globalA, &globalB );
     82                signal_op( globalA, globalB );
    8383        }
    8484}
    8585
    8686//------------------------------------------------------------------------------
    87 void barge_op( global_data_t * mutex a ) {
    88         a->last_thread = this_thread;
     87void barge_op( global_data_t & mutex a ) {
     88        a.last_thread = this_thread;
    8989}
    9090
    9191thread Barger {};
    92 void main( Barger* this ) {
     92void main( Barger & this ) {
    9393        for( unsigned i = 0; !done; i++ ) {
    9494                //Choose some monitor to barge into with some irregular pattern
    9595                bool choose_a = (i % 13) > (i % 17);
    96                 barge_op( choose_a ? &globalA : &globalB );
     96                if ( choose_a ) barge_op( globalA );
     97                else barge_op( globalB );
    9798        }
    9899}
  • src/tests/sched-int-disjoint.c

    r8499c707 r83a071f9  
    3535//------------------------------------------------------------------------------
    3636// Barging logic
    37 void barge( global_data_t * mutex d ) {
    38         d->state = BARGE;
     37void barge( global_data_t & mutex d ) {
     38        d.state = BARGE;
    3939}
    4040
    4141thread Barger {};
    4242
    43 void main( Barger * this ) {
     43void main( Barger & this ) {
    4444        while( !all_done ) {
    45                 barge( &data );
     45                barge( data );
    4646                yield();
    4747        }
     
    5050//------------------------------------------------------------------------------
    5151// Waiting logic
    52 bool wait( global_t * mutex m, global_data_t * mutex d ) {
     52bool wait( global_t & mutex m, global_data_t & mutex d ) {
    5353        wait( &cond );
    54         if( d->state != SIGNAL ) {
     54        if( d.state != SIGNAL ) {
    5555                sout | "ERROR barging!" | endl;
    5656        }
    5757
    58         d->counter++;
     58        d.counter++;
    5959
    60         if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
     60        if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
    6161
    62         return d->counter < N;
     62        return d.counter < N;
    6363}
    6464
    6565thread Waiter {};
    6666
    67 void main( Waiter * this ) {
    68         while( wait( &mut, &data ) ) { yield(); }
     67void main( Waiter & this ) {
     68        while( wait( mut, data ) ) { yield(); }
    6969}
    7070
     
    7272//------------------------------------------------------------------------------
    7373// Signalling logic
    74 void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
    75         b->state = SIGNAL;
     74void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) {
     75        b.state = SIGNAL;
    7676        signal( cond );
    7777}
    7878
    79 void logic( global_t * mutex a ) {
    80         signal( &cond, a, &data );
     79void logic( global_t & mutex a ) {
     80        signal( &cond, a, data );
    8181
    8282        yield( (unsigned)rand48() % 10 );
     
    9191thread Signaller {};
    9292
    93 void main( Signaller * this ) {
     93void main( Signaller & this ) {
    9494        while( !all_done ) {
    95                 logic( &mut );
     95                logic( mut );
    9696                yield();
    9797        }
  • src/tests/sched-int-wait.c

    r8499c707 r83a071f9  
    2727//----------------------------------------------------------------------------------------------------
    2828// Tools
    29 void signal( condition * cond, global_t * mutex a, global_t * mutex b ) {
     29void signal( condition * cond, global_t & mutex a, global_t & mutex b ) {
    3030        signal( cond );
    3131}
    3232
    33 void signal( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
     33void signal( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) {
    3434        signal( cond );
    3535}
    3636
    37 void wait( condition * cond, global_t * mutex a, global_t * mutex b ) {
     37void wait( condition * cond, global_t & mutex a, global_t & mutex b ) {
    3838        wait( cond );
    3939}
    4040
    41 void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
     41void wait( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) {
    4242        wait( cond );
    4343}
     
    4545//----------------------------------------------------------------------------------------------------
    4646// Signaler
    47 void main( Signaler* this ) {
     47void main( Signaler & this ) {
    4848
    4949        while( waiter_left != 0 ) {
     
    5151                switch( action ) {
    5252                        case 0:
    53                                 signal( &condABC, &globalA, &globalB, &globalC );
     53                                signal( &condABC, globalA, globalB, globalC );
    5454                                break;
    5555                        case 1:
    56                                 signal( &condAB , &globalA, &globalB );
     56                                signal( &condAB , globalA, globalB );
    5757                                break;
    5858                        case 2:
    59                                 signal( &condBC , &globalB, &globalC );
     59                                signal( &condBC , globalB, globalC );
    6060                                break;
    6161                        case 3:
    62                                 signal( &condAC , &globalA, &globalC );
     62                                signal( &condAC , globalA, globalC );
    6363                                break;
    6464                        default:
     
    7272//----------------------------------------------------------------------------------------------------
    7373// Waiter ABC
    74 void main( WaiterABC* this ) {
     74void main( WaiterABC & this ) {
    7575        for( int i = 0; i < N; i++ ) {
    76                 wait( &condABC, &globalA, &globalB, &globalC );
     76                wait( &condABC, globalA, globalB, globalC );
    7777        }
    7878
     
    8282//----------------------------------------------------------------------------------------------------
    8383// Waiter AB
    84 void main( WaiterAB* this ) {
     84void main( WaiterAB & this ) {
    8585        for( int i = 0; i < N; i++ ) {
    86                 wait( &condAB , &globalA, &globalB );
     86                wait( &condAB , globalA, globalB );
    8787        }
    8888
     
    9292//----------------------------------------------------------------------------------------------------
    9393// Waiter AC
    94 void main( WaiterAC* this ) {
     94void main( WaiterAC & this ) {
    9595        for( int i = 0; i < N; i++ ) {
    96                 wait( &condAC , &globalA, &globalC );
     96                wait( &condAC , globalA, globalC );
    9797        }
    9898
     
    102102//----------------------------------------------------------------------------------------------------
    103103// Waiter BC
    104 void main( WaiterBC* this ) {
     104void main( WaiterBC & this ) {
    105105        for( int i = 0; i < N; i++ ) {
    106                 wait( &condBC , &globalB, &globalC );
     106                wait( &condBC , globalB, globalC );
    107107        }
    108108
  • src/tests/thread.c

    r8499c707 r83a071f9  
    77thread Second { semaphore* lock; };
    88
    9 void ?{}( First & this, semaphore* lock ) { this.lock = lock; }
    10 void ?{}( Second & this, semaphore* lock ) { this.lock = lock; }
     9void ?{}( First & this, semaphore & lock ) { this.lock = &lock; }
     10void ?{}( Second & this, semaphore & lock ) { this.lock = &lock; }
    1111
    12 void main(First* this) {
     12void main(First& this) {
    1313        for(int i = 0; i < 10; i++) {
    1414                sout | "First : Suspend No." | i + 1 | endl;
    1515                yield();
    1616        }
    17         V(this->lock);
     17        V(this.lock);
    1818}
    1919
    20 void main(Second* this) {
    21         P(this->lock);
     20void main(Second& this) {
     21        P(this.lock);
    2222        for(int i = 0; i < 10; i++) {
    2323                sout | "Second : Suspend No." | i + 1 | endl;
     
    3333                processor p;
    3434                {
    35                         First  f = { &lock };
    36                         Second s = { &lock };
     35                        First  f = { lock };
     36                        Second s = { lock };
    3737                }
    3838        }
Note: See TracChangeset for help on using the changeset viewer.