Ignore:
Timestamp:
Dec 7, 2016, 2:47:53 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
550a338
Parents:
a68caae
Message:

Coroutines no longer require virtual pointers or any code beyond the get_coroutine routine

File:
1 edited

Legend:

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

    ra68caae r80d9e49  
    3434static size_t pageSize = 0;                             // architecture pagesize
    3535
    36 static coroutine main_coroutine;
     36void ?{}(coStack_t* this, size_t size);
     37void ?{}(coroutine* this, size_t size);
     38
     39static coroutine main_coroutine = { 1000 };
    3740static coroutine* current_coroutine = &main_coroutine;
    3841
     
    4346void ctxSwitchDirect(coroutine* src, coroutine* dst);
    4447void create_stack( coStack_t* this, unsigned int storageSize ); // used by all constructors
     48
     49extern "C" {
     50      forall(dtype T | is_coroutine(T))
     51      void invokeCoroutine(T* this);
     52
     53      forall(dtype T | is_coroutine(T))
     54      void startCoroutine(T* this, void (*invoke)(T*));
     55}
    4556
    4657void ?{}(coStack_t* this) {
     
    5263        this->top               = NULL; // address of top of storage
    5364        this->userStack = false;       
     65}
     66
     67void ?{}(coStack_t* this, size_t size) {
     68        this{};
     69        this->size = size;
    5470
    5571        create_stack(this, this->size);
     
    6682}
    6783
    68 void ?{}(coroutine* this, covptr_t* object)
     84void ?{}(coroutine* this, size_t size)
    6985{
    7086        this{};
    71 
    72         startCoroutine(object, invokeCoroutine);
     87        (&this->stack){size};
    7388}
    7489
     
    88103}
    89104
    90 forall(dtype T | coroutine_t(T))
     105forall(dtype T | is_coroutine(T))
    91106void resume(T* cor) {
    92107        coroutine* src = this_coroutine();              // optimization
    93         coroutine* dst = get_coroutine(vtable(cor));
     108        coroutine* dst = get_coroutine(cor);
     109
     110        if( ((intptr_t)dst->stack.base) == 0 ) {
     111                create_stack(&dst->stack, dst->stack.size);
     112                startCoroutine(cor, invokeCoroutine);
     113        }
    94114
    95115        if ( src != dst ) {                             // not resuming self ?
     
    103123}
    104124
     125forall(dtype T | is_coroutine(T))
     126void prime(T* cor) {
     127        coroutine* this = get_coroutine(cor);
     128        assert(this->state == Start);
     129
     130        this->state = Primed;
     131        resume(cor);
     132}
     133
    105134void ctxSwitchDirect(coroutine* src, coroutine* dst) {
    106135        // THREAD_GETMEM( This )->disableInterrupts();
Note: See TracChangeset for help on using the changeset viewer.