Changeset c3acb841
- Timestamp:
- Mar 15, 2017, 4:10:41 PM (7 years ago)
- 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:
- 84c52a8
- Parents:
- 0e7b95c
- Location:
- src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/CorCtxSwitch.c
r0e7b95c rc3acb841 24 24 25 25 struct GreatSuspender { 26 coroutine c;26 coroutine_desc c; 27 27 }; 28 28 -
src/benchmark/bench.c
r0e7b95c rc3acb841 86 86 //======================================= 87 87 88 struct CoroutineDummy { coroutine c; };88 struct CoroutineDummy { coroutine_desc c; }; 89 89 DECL_COROUTINE(CoroutineDummy); 90 90 void main(CoroutineDummy * this) {} … … 119 119 struct CoroutineResume { 120 120 int N; 121 coroutine c;121 coroutine_desc c; 122 122 }; 123 123 -
src/benchmark/csv-data.c
r0e7b95c rc3acb841 26 26 27 27 struct GreatSuspender { 28 coroutine c;28 coroutine_desc c; 29 29 }; 30 30 -
src/libcfa/concurrency/coroutine
r0e7b95c rc3acb841 27 27 trait is_coroutine(dtype T) { 28 28 void main(T * this); 29 coroutine * get_coroutine(T * this);29 coroutine_desc * get_coroutine(T * this); 30 30 }; 31 31 32 #define DECL_COROUTINE(X) static inline coroutine * get_coroutine(X* this) { return &this->c; } void main(X* this)32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->c; } void main(X* this) 33 33 34 34 //----------------------------------------------------------------------------- 35 35 // Ctors and dtors 36 36 void ?{}(coStack_t * this); 37 void ?{}(coroutine * this);38 void ?{}(coroutine * this, const char * name);37 void ?{}(coroutine_desc * this); 38 void ?{}(coroutine_desc * this, const char * name); 39 39 void ^?{}(coStack_t * this); 40 void ^?{}(coroutine * this);40 void ^?{}(coroutine_desc * this); 41 41 42 42 //----------------------------------------------------------------------------- … … 63 63 64 64 // Get current coroutine 65 coroutine * this_coroutine(void);65 coroutine_desc * this_coroutine(void); 66 66 67 67 // Private wrappers for context switch and stack creation 68 extern void CoroutineCtxSwitch(coroutine * src, coroutine* dst);68 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 69 69 extern void create_stack( coStack_t * this, unsigned int storageSize ); 70 70 71 71 // Suspend implementation inlined for performance 72 72 static inline void suspend() { 73 coroutine * src = this_coroutine(); // optimization73 coroutine_desc * src = this_coroutine(); // optimization 74 74 75 75 assertf( src->last != 0, … … 88 88 forall(dtype T | is_coroutine(T)) 89 89 static inline void resume(T * cor) { 90 coroutine * src = this_coroutine(); // optimization91 coroutine * dst = get_coroutine(cor);90 coroutine_desc * src = this_coroutine(); // optimization 91 coroutine_desc * dst = get_coroutine(cor); 92 92 93 93 if( unlikely(!dst->stack.base) ) { … … 111 111 } 112 112 113 static inline void resume(coroutine * dst) {114 coroutine * src = this_coroutine(); // optimization113 static inline void resume(coroutine_desc * dst) { 114 coroutine_desc * src = this_coroutine(); // optimization 115 115 116 116 // not resuming self ? -
src/libcfa/concurrency/coroutine.c
r0e7b95c rc3acb841 60 60 } 61 61 62 void ?{}(coroutine * this) {62 void ?{}(coroutine_desc* this) { 63 63 this{ "Anonymous Coroutine" }; 64 64 } 65 65 66 void ?{}(coroutine * this, const char * name) {66 void ?{}(coroutine_desc* this, const char * name) { 67 67 this->name = name; 68 68 this->errno_ = 0; … … 72 72 } 73 73 74 void ?{}(coroutine * this, size_t size) {74 void ?{}(coroutine_desc* this, size_t size) { 75 75 this{}; 76 76 (&this->stack){size}; … … 88 88 } 89 89 90 void ^?{}(coroutine * this) {}90 void ^?{}(coroutine_desc* this) {} 91 91 92 92 // Part of the Public API … … 94 94 forall(dtype T | is_coroutine(T)) 95 95 void prime(T* cor) { 96 coroutine * this = get_coroutine(cor);96 coroutine_desc* this = get_coroutine(cor); 97 97 assert(this->state == Start); 98 98 … … 102 102 103 103 // Wrapper for co 104 void CoroutineCtxSwitch(coroutine * src, coroutine* dst) {104 void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 105 105 // THREAD_GETMEM( This )->disableInterrupts(); 106 106 -
src/libcfa/concurrency/invoke.c
r0e7b95c rc3acb841 33 33 void CtxInvokeCoroutine( 34 34 void (*main)(void *), 35 struct coroutine *(*get_coroutine)(void *),35 struct coroutine_desc *(*get_coroutine)(void *), 36 36 void *this 37 37 ) { 38 38 // LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine); 39 39 40 struct coroutine * cor = get_coroutine( this );40 struct coroutine_desc* cor = get_coroutine( this ); 41 41 42 42 if(cor->state == Primed) { … … 63 63 64 64 struct thread* thrd = get_thread( this ); 65 struct coroutine * cor = &thrd->c;65 struct coroutine_desc* cor = &thrd->c; 66 66 cor->state = Active; 67 67 … … 79 79 void CtxStart( 80 80 void (*main)(void *), 81 struct coroutine *(*get_coroutine)(void *),81 struct coroutine_desc *(*get_coroutine)(void *), 82 82 void *this, 83 83 void (*invoke)(void *) -
src/libcfa/concurrency/invoke.h
r0e7b95c rc3acb841 71 71 enum coroutine_state { Halted, Start, Inactive, Active, Primed }; 72 72 73 struct coroutine {73 struct coroutine_desc { 74 74 struct coStack_t stack; 75 75 const char *name; // textual name for coroutine/task, initialized by uC++ generated code 76 76 int errno_; // copy of global UNIX variable errno 77 77 enum coroutine_state state; // current execution status for coroutine 78 struct coroutine *starter; // first coroutine to resume this one79 struct coroutine *last; // last coroutine to resume this one78 struct coroutine_desc *starter; // first coroutine to resume this one 79 struct coroutine_desc *last; // last coroutine to resume this one 80 80 }; 81 81 82 82 struct thread { 83 struct coroutine c; // coroutine body used to store context83 struct coroutine_desc c; // coroutine body used to store context 84 84 struct signal_once terminated; // indicate if execuation state is not halted 85 85 struct thread * next; // instrusive link field for threads -
src/libcfa/concurrency/kernel
r0e7b95c rc3acb841 62 62 struct processorCtx_t * runner; 63 63 cluster * cltr; 64 coroutine * current_coroutine;64 coroutine_desc * current_coroutine; 65 65 thread * current_thread; 66 66 pthread_t kernel_thread; -
src/libcfa/concurrency/kernel.c
r0e7b95c rc3acb841 55 55 thread_local processor * this_processor; 56 56 57 coroutine * this_coroutine(void) {57 coroutine_desc * this_coroutine(void) { 58 58 return this_processor->current_coroutine; 59 59 } … … 99 99 } 100 100 101 void ?{}( coroutine * this, current_stack_info_t * info) {101 void ?{}( coroutine_desc * this, current_stack_info_t * info) { 102 102 (&this->stack){ info }; 103 103 this->name = "Main Thread"; … … 203 203 // from the processor coroutine to the target thread 204 204 void runThread(processor * this, thread * dst) { 205 coroutine * proc_cor = get_coroutine(this->runner);206 coroutine * thrd_cor = get_coroutine(dst);205 coroutine_desc * proc_cor = get_coroutine(this->runner); 206 coroutine_desc * thrd_cor = get_coroutine(dst); 207 207 208 208 //Reset the terminating actions here -
src/libcfa/concurrency/kernel_private.h
r0e7b95c rc3acb841 35 35 struct processorCtx_t { 36 36 processor * proc; 37 coroutine c;37 coroutine_desc c; 38 38 }; 39 39 … … 53 53 } 54 54 55 extern void ThreadCtxSwitch(coroutine * src, coroutine* dst);55 extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 56 56 57 57 #endif //KERNEL_PRIVATE_H -
src/libcfa/concurrency/thread
r0e7b95c rc3acb841 35 35 36 36 forall( dtype T | is_thread(T) ) 37 static inline coroutine * get_coroutine(T* this) {37 static inline coroutine_desc* get_coroutine(T* this) { 38 38 return &get_thread(this)->c; 39 39 } 40 40 41 static inline coroutine * get_coroutine(thread* this) {41 static inline coroutine_desc* get_coroutine(thread* this) { 42 42 return &this->c; 43 43 } -
src/libcfa/concurrency/thread.c
r0e7b95c rc3acb841 74 74 forall( dtype T | is_thread(T) ) 75 75 void start( T* this ) { 76 coroutine * thrd_c = get_coroutine(this);76 coroutine_desc* thrd_c = get_coroutine(this); 77 77 thread* thrd_h = get_thread (this); 78 78 thrd_c->last = this_coroutine(); … … 97 97 } 98 98 99 void ThreadCtxSwitch(coroutine * src, coroutine* dst) {99 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 100 100 // set state of current coroutine to inactive 101 101 src->state = Inactive; -
src/tests/coroutine.c
r0e7b95c rc3acb841 4 4 struct Fibonacci { 5 5 int fn; // used for communication 6 coroutine c;6 coroutine_desc c; 7 7 }; 8 8 … … 11 11 } 12 12 13 coroutine * get_coroutine(Fibonacci* this) {13 coroutine_desc* get_coroutine(Fibonacci* this) { 14 14 return &this->c; 15 15 } … … 47 47 #ifdef MORE_DEBUG 48 48 Fibonacci *pf1 = &f1, *pf2 = &f2; 49 coroutine *cf1 = &f1.c, *cf2 = &f2.c;49 coroutine_desc *cf1 = &f1.c, *cf2 = &f2.c; 50 50 covptr_t *vf1 = vtable(pf1), *vf2 = vtable(pf2); 51 coroutine *cv1 = get_coroutine(vf1), *cv2 = get_coroutine(vf2);51 coroutine_desc *cv1 = get_coroutine(vf1), *cv2 = get_coroutine(vf2); 52 52 Fibonacci *ov1 = (Fibonacci *)get_object(vf1), *ov2 = (Fibonacci *)get_object(vf2); 53 53
Note: See TracChangeset
for help on using the changeset viewer.