Changeset 80d9e49 for src/libcfa/concurrency/threads.c
- Timestamp:
- Dec 7, 2016, 2:47:53 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:
- 550a338
- Parents:
- a68caae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/threads.c
ra68caae r80d9e49 34 34 static size_t pageSize = 0; // architecture pagesize 35 35 36 static coroutine main_coroutine; 36 void ?{}(coStack_t* this, size_t size); 37 void ?{}(coroutine* this, size_t size); 38 39 static coroutine main_coroutine = { 1000 }; 37 40 static coroutine* current_coroutine = &main_coroutine; 38 41 … … 43 46 void ctxSwitchDirect(coroutine* src, coroutine* dst); 44 47 void create_stack( coStack_t* this, unsigned int storageSize ); // used by all constructors 48 49 extern "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 } 45 56 46 57 void ?{}(coStack_t* this) { … … 52 63 this->top = NULL; // address of top of storage 53 64 this->userStack = false; 65 } 66 67 void ?{}(coStack_t* this, size_t size) { 68 this{}; 69 this->size = size; 54 70 55 71 create_stack(this, this->size); … … 66 82 } 67 83 68 void ?{}(coroutine* this, covptr_t* object)84 void ?{}(coroutine* this, size_t size) 69 85 { 70 86 this{}; 71 72 startCoroutine(object, invokeCoroutine); 87 (&this->stack){size}; 73 88 } 74 89 … … 88 103 } 89 104 90 forall(dtype T | coroutine_t(T))105 forall(dtype T | is_coroutine(T)) 91 106 void resume(T* cor) { 92 107 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 } 94 114 95 115 if ( src != dst ) { // not resuming self ? … … 103 123 } 104 124 125 forall(dtype T | is_coroutine(T)) 126 void prime(T* cor) { 127 coroutine* this = get_coroutine(cor); 128 assert(this->state == Start); 129 130 this->state = Primed; 131 resume(cor); 132 } 133 105 134 void ctxSwitchDirect(coroutine* src, coroutine* dst) { 106 135 // THREAD_GETMEM( This )->disableInterrupts();
Note: See TracChangeset
for help on using the changeset viewer.