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