- File:
-
- 1 edited
-
src/libcfa/concurrency/coroutine (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/coroutine
r83a071f9 r6b0b624 10 10 // Author : Thierry Delisle 11 11 // Created On : Mon Nov 28 12:27:26 2016 12 // Last Modified By : Thierry Delisle13 // Last Modified On : Mon Nov 28 12:27:26 201614 // Update Count : 012 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sat Jul 22 09:57:17 2017 14 // Update Count : 2 15 15 // 16 16 17 #ifndef COROUTINES_H 18 #define COROUTINES_H 17 #pragma once 19 18 20 #include "assert"19 #include <assert.h> 21 20 #include "invoke.h" 22 21 … … 26 25 // Anything that is resumed is a coroutine. 27 26 trait is_coroutine(dtype T) { 28 void main(T &this);29 coroutine_desc * get_coroutine(T &this);27 void main(T * this); 28 coroutine_desc * get_coroutine(T * this); 30 29 }; 31 30 32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X & this) { return &this.__cor; } void main(X&this)31 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this) 33 32 34 33 //----------------------------------------------------------------------------- 35 34 // Ctors and dtors 36 void ?{}(coStack_t &this);37 void ?{}(coroutine_desc &this);38 void ?{}(coroutine_desc &this, const char * name);39 void ^?{}(coStack_t &this);40 void ^?{}(coroutine_desc &this);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); 41 40 42 41 //----------------------------------------------------------------------------- … … 45 44 46 45 forall(dtype T | is_coroutine(T)) 47 static inline void resume(T &cor);46 static inline void resume(T * cor); 48 47 49 48 forall(dtype T | is_coroutine(T)) 50 void prime(T &cor);49 void prime(T * cor); 51 50 52 51 //----------------------------------------------------------------------------- … … 63 62 64 63 // Get current coroutine 65 extern volatile thread_local coroutine_desc *this_coroutine;64 extern thread_local coroutine_desc * volatile this_coroutine; 66 65 67 66 // Private wrappers for context switch and stack creation … … 87 86 // Resume implementation inlined for performance 88 87 forall(dtype T | is_coroutine(T)) 89 static inline void resume(T &cor) {88 static inline void resume(T * cor) { 90 89 coroutine_desc * src = this_coroutine; // optimization 91 90 coroutine_desc * dst = get_coroutine(cor); … … 93 92 if( unlikely(!dst->stack.base) ) { 94 93 create_stack(&dst->stack, dst->stack.size); 95 CtxStart( &cor, CtxInvokeCoroutine);94 CtxStart(cor, CtxInvokeCoroutine); 96 95 } 97 96 … … 129 128 } 130 129 131 #endif //COROUTINES_H132 133 130 // Local Variables: // 134 131 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.