Ignore:
Timestamp:
Feb 14, 2017, 1:19:28 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
97d246d
Parents:
f923b5f (diff), eafb094 (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:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rf923b5f rd3a804f5  
    1717#include "threads"
    1818
    19 #include "kernel"
     19#include "kernel_private.h"
    2020#include "libhdr.h"
    2121
     
    2424
    2525extern "C" {
     26        #include <fenv.h>
    2627        #include <stddef.h>
    2728}
     
    4344        (&this->c){};
    4445        this->c.name = "Anonymous Coroutine";
    45         (&this->lock){};
     46        (&this->terminated){};
    4647        this->next = NULL;
    4748}
     
    7172//-----------------------------------------------------------------------------
    7273// Starting and stopping threads
    73 extern "C" {
    74       forall(dtype T | is_thread(T))
    75       void CtxInvokeThread(T * this);
    76 }
    77 
    78 extern void thread_schedule( thread * );
    79 
    8074forall( dtype T | is_thread(T) )
    8175void start( T* this ) {
     
    9185        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
    9286
    93         LIB_DEBUG_PRINTF("Thread started : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
    94 
    95         thread_schedule(thrd_h);
     87        ScheduleThread(thrd_h);
    9688}
    9789
    9890forall( dtype T | is_thread(T) )
    9991void stop( T* this ) {
    100         thread*  thrd = get_thread(this);
    101         if( thrd->c.notHalted ) {
    102                 lock( &thrd->lock );
    103         }
     92        wait( & get_thread(this)->terminated );
    10493}
    10594
    10695void yield( void ) {
    107         thread_schedule( this_thread() );
    108         suspend();
     96        ScheduleInternal( get_this_processor()->current_thread );
    10997}
    11098
    11199void 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
    112105        dst->last = src;
    113106
    114         // set state of current coroutine to inactive
    115         src->state = Inactive;
    116 
    117         // set new coroutine that task is executing
     107        // set new coroutine that the processor is executing
     108        // and context switch to it
    118109        get_this_processor()->current_coroutine = dst; 
    119 
    120         // context switch to specified coroutine
    121110        CtxSwitch( src->stack.context, dst->stack.context );
    122         // when CtxSwitch returns we are back in the src coroutine
     111        get_this_processor()->current_coroutine = src; 
    123112
    124113        // set state of new coroutine to active
     114        dst->state = Inactive;
    125115        src->state = Active;
    126116}
     
    130120extern "C" {
    131121        void __thread_signal_termination( thread * this ) {
    132                 this->c.state = Halt;
    133                 this->c.notHalted = false;
    134                 unlock( &this->lock );
     122                this->c.state = Halted;
     123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
     124                signal( &this->terminated );   
    135125        }
    136126}
Note: See TracChangeset for help on using the changeset viewer.