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

Fix concurrency library, tests, and keywords for references

Location:
src/libcfa/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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 );
Note: See TracChangeset for help on using the changeset viewer.