Ignore:
Timestamp:
Feb 15, 2017, 8:13:49 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:
e6512c8
Parents:
aa9ee19 (diff), 3149e7e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/threads.c

    raa9ee19 r97f65d5  
    1717#include "threads"
    1818
    19 #include "kernel"
     19#include "kernel_private.h"
    2020#include "libhdr.h"
    2121
     
    4444        (&this->c){};
    4545        this->c.name = "Anonymous Coroutine";
    46         (&this->lock){};
     46        (&this->terminated){};
    4747        this->next = NULL;
    4848}
     
    7272//-----------------------------------------------------------------------------
    7373// Starting and stopping threads
    74 extern "C" {
    75       forall(dtype T | is_thread(T))
    76       void CtxInvokeThread(T * this);
    77 }
    78 
    79 extern void thread_schedule( thread * );
    80 
    8174forall( dtype T | is_thread(T) )
    8275void start( T* this ) {
     
    9285        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
    9386
    94         fenv_t envp;
    95         fegetenv( &envp );
    96         LIB_DEBUG_PRINTF("Thread : mxcsr %x\n", envp.__mxcsr);
    97         LIB_DEBUG_PRINTF("Thread started : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
    98 
    99         thread_schedule(thrd_h);
     87        ScheduleThread(thrd_h);
    10088}
    10189
    10290forall( dtype T | is_thread(T) )
    10391void stop( T* this ) {
    104         thread*  thrd = get_thread(this);
    105         if( thrd->c.notHalted ) {
    106                 lock( &thrd->lock );
    107         }
     92        wait( & get_thread(this)->terminated );
    10893}
    10994
    11095void yield( void ) {
    111         get_this_processor()->thread_action = Reschedule;
    112         suspend();
     96        ScheduleInternal( get_this_processor()->current_thread );
    11397}
    11498
    11599void ThreadCtxSwitch(coroutine* src, coroutine* dst) {
     100        // set state of current coroutine to inactive
     101        src->state = Inactive;
     102        dst->state = Active;
     103
     104        //update the last resumer
    116105        dst->last = src;
    117106
    118         // set state of current coroutine to inactive
    119         src->state = Inactive;
    120 
    121         // set new coroutine that task is executing
     107        // set new coroutine that the processor is executing
     108        // and context switch to it
    122109        get_this_processor()->current_coroutine = dst; 
    123 
    124         // context switch to specified coroutine
    125110        CtxSwitch( src->stack.context, dst->stack.context );
    126         // when CtxSwitch returns we are back in the src coroutine
     111        get_this_processor()->current_coroutine = src; 
    127112
    128113        // set state of new coroutine to active
     114        dst->state = Inactive;
    129115        src->state = Active;
    130116}
     
    134120extern "C" {
    135121        void __thread_signal_termination( thread * this ) {
    136                 this->c.state = Halt;
    137                 this->c.notHalted = false;
    138                 unlock( &this->lock );
     122                this->c.state = Halted;
     123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
     124                signal( &this->terminated );   
    139125        }
    140126}
Note: See TracChangeset for help on using the changeset viewer.