Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutine

    r6b0b624 r83a071f9  
    1010// Author           : Thierry Delisle
    1111// Created On       : Mon Nov 28 12:27:26 2016
    12 // Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sat Jul 22 09:57:17 2017
    14 // Update Count     : 2
     12// Last Modified By : Thierry Delisle
     13// Last Modified On : Mon Nov 28 12:27:26 2016
     14// Update Count     : 0
    1515//
    1616
    17 #pragma once
     17#ifndef COROUTINES_H
     18#define COROUTINES_H
    1819
    19 #include <assert.h>
     20#include "assert"
    2021#include "invoke.h"
    2122
     
    2526// Anything that is resumed is a coroutine.
    2627trait is_coroutine(dtype T) {
    27       void main(T * this);
    28       coroutine_desc * get_coroutine(T * this);
     28      void main(T & this);
     29      coroutine_desc * get_coroutine(T & this);
    2930};
    3031
    31 #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)
    3233
    3334//-----------------------------------------------------------------------------
    3435// Ctors and dtors
    35 void ?{}(coStack_t * this);
    36 void ?{}(coroutine_desc * this);
    37 void ?{}(coroutine_desc * this, const char * name);
    38 void ^?{}(coStack_t * this);
    39 void ^?{}(coroutine_desc * this);
     36void ?{}(coStack_t & this);
     37void ?{}(coroutine_desc & this);
     38void ?{}(coroutine_desc & this, const char * name);
     39void ^?{}(coStack_t & this);
     40void ^?{}(coroutine_desc & this);
    4041
    4142//-----------------------------------------------------------------------------
     
    4445
    4546forall(dtype T | is_coroutine(T))
    46 static inline void resume(T * cor);
     47static inline void resume(T & cor);
    4748
    4849forall(dtype T | is_coroutine(T))
    49 void prime(T * cor);
     50void prime(T & cor);
    5051
    5152//-----------------------------------------------------------------------------
     
    6263
    6364// Get current coroutine
    64 extern thread_local coroutine_desc * volatile this_coroutine;
     65extern volatile thread_local coroutine_desc * this_coroutine;
    6566
    6667// Private wrappers for context switch and stack creation
     
    8687// Resume implementation inlined for performance
    8788forall(dtype T | is_coroutine(T))
    88 static inline void resume(T * cor) {
     89static inline void resume(T & cor) {
    8990        coroutine_desc * src = this_coroutine;          // optimization
    9091        coroutine_desc * dst = get_coroutine(cor);
     
    9293        if( unlikely(!dst->stack.base) ) {
    9394                create_stack(&dst->stack, dst->stack.size);
    94                 CtxStart(cor, CtxInvokeCoroutine);
     95                CtxStart(&cor, CtxInvokeCoroutine);
    9596        }
    9697
     
    128129}
    129130
     131#endif //COROUTINES_H
     132
    130133// Local Variables: //
    131134// mode: c //
Note: See TracChangeset for help on using the changeset viewer.