Changeset b2f6113 for libcfa/src
- Timestamp:
- Apr 4, 2019, 3:37:55 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8c01e1b
- Parents:
- 2fabdc02
- Location:
- libcfa/src/concurrency
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/CtxSwitch-i386.S
r2fabdc02 rb2f6113 53 53 // Save floating & SSE control words on the stack. 54 54 55 56 57 55 sub $8,%esp 56 stmxcsr 0(%esp) // 4 bytes 57 fnstcw 4(%esp) // 2 bytes 58 58 59 59 // Save volatile registers on the stack. … … 67 67 movl %esp,SP_OFFSET(%eax) 68 68 movl %ebp,FP_OFFSET(%eax) 69 // movl 4(%ebp),%ebx // save previous eip for debugger70 // movl %ebx,PC_OFFSET(%eax)71 69 72 70 // Copy the "to" context argument from the stack to register eax … … 89 87 // Load floating & SSE control words from the stack. 90 88 91 92 93 89 fldcw 4(%esp) 90 ldmxcsr 0(%esp) 91 add $8,%esp 94 92 95 93 // Return to thread. -
libcfa/src/concurrency/CtxSwitch-x86_64.S
r2fabdc02 rb2f6113 39 39 #define SP_OFFSET ( 0 * PTR_BYTE ) 40 40 #define FP_OFFSET ( 1 * PTR_BYTE ) 41 #define PC_OFFSET ( 2 * PTR_BYTE )42 41 43 42 .text -
libcfa/src/concurrency/coroutine.cfa
r2fabdc02 rb2f6113 35 35 36 36 extern "C" { 37 38 39 40 41 37 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__)); 38 static void _CtxCoroutine_UnwindCleanup(_Unwind_Reason_Code, struct _Unwind_Exception *) __attribute__ ((__noreturn__)); 39 static void _CtxCoroutine_UnwindCleanup(_Unwind_Reason_Code, struct _Unwind_Exception *) { 40 abort(); 41 } 42 42 } 43 43 … … 47 47 // minimum feasible stack size in bytes 48 48 #define MinStackSize 1000 49 static size_t pageSize = 0; // architecture pagesize HACK, should go in proper runtime singleton 49 extern size_t __page_size; // architecture pagesize HACK, should go in proper runtime singleton 50 51 void __stack_prepare( __stack_info_t * this, size_t create_size ); 50 52 51 53 //----------------------------------------------------------------------------- 52 54 // Coroutine ctors and dtors 53 void ?{}( coStack_t & this, void * storage, size_t storageSize ) with( this ) { 54 size = storageSize == 0 ? 65000 : storageSize; // size of stack 55 this.storage = storage; // pointer to stack 56 limit = NULL; // stack grows towards stack limit 57 base = NULL; // base of stack 58 context = NULL; // address of cfa_context_t 59 top = NULL; // address of top of storage 60 userStack = storage != NULL; 61 } 62 63 void ^?{}(coStack_t & this) { 64 if ( ! this.userStack && this.storage ) { 65 __cfaabi_dbg_debug_do( 66 if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) { 67 abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 68 } 69 ); 70 free( this.storage ); 71 } 55 void ?{}( __stack_info_t & this, void * storage, size_t storageSize ) { 56 this.storage = (__stack_t *)storage; 57 58 // Did we get a piece of storage ? 59 if (this.storage || storageSize != 0) { 60 // We either got a piece of storage or the user asked for a specific size 61 // Immediately create the stack 62 // (This is slightly unintuitive that non-default sized coroutines create are eagerly created 63 // but it avoids that all coroutines carry an unnecessary size) 64 verify( storageSize != 0 ); 65 __stack_prepare( &this, storageSize ); 66 } 67 } 68 69 void ^?{}(__stack_info_t & this) { 70 if ( ! this.userStack && this.storage ) { 71 void * storage = (char*)(this.storage) - this.storage->size; 72 __cfaabi_dbg_debug_do( 73 storage = (char*)(storage) - __page_size; 74 if ( mprotect( storage, __page_size, PROT_READ | PROT_WRITE ) == -1 ) { 75 abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 76 } 77 ); 78 __cfaabi_dbg_print_safe("Kernel : Deleting stack %p\n", storage); 79 free( storage ); 80 } 72 81 } 73 82 74 83 void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize ) with( this ) { 75 (this.stack){storage, storageSize}; 76 this.name = name; 77 errno_ = 0; 78 state = Start; 79 starter = NULL; 80 last = NULL; 81 cancellation = NULL; 84 (this.stack){storage, storageSize}; 85 this.name = name; 86 state = Start; 87 starter = NULL; 88 last = NULL; 89 cancellation = NULL; 82 90 } 83 91 84 92 void ^?{}(coroutine_desc& this) { 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 93 if(this.state != Halted && this.state != Start) { 94 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 95 coroutine_desc * dst = &this; 96 97 struct _Unwind_Exception storage; 98 storage.exception_class = -1; 99 storage.exception_cleanup = _CtxCoroutine_UnwindCleanup; 100 this.cancellation = &storage; 101 this.last = src; 102 103 // not resuming self ? 104 if ( src == dst ) { 105 abort( "Attempt by coroutine %.256s (%p) to terminate itself.\n", src->name, src ); 106 } 107 108 CoroutineCtxSwitch( src, dst ); 109 } 102 110 } 103 111 … … 106 114 forall(dtype T | is_coroutine(T)) 107 115 void prime(T& cor) { 108 109 110 111 112 116 coroutine_desc* this = get_coroutine(cor); 117 assert(this->state == Start); 118 119 this->state = Primed; 120 resume(cor); 113 121 } 114 122 115 123 // Wrapper for co 116 124 void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 117 // Safety note : Preemption must be disabled since there is a race condition 118 // kernelTLS.this_thread->curr_cor and $rsp/$rbp must agree at all times 119 verify( TL_GET( preemption_state.enabled ) || TL_GET( this_processor )->do_terminate ); 120 disable_interrupts(); 121 122 // set state of current coroutine to inactive 123 src->state = src->state == Halted ? Halted : Inactive; 124 125 // set new coroutine that task is executing 126 TL_GET( this_thread )->curr_cor = dst; 127 128 // context switch to specified coroutine 129 assert( src->stack.context ); 130 CtxSwitch( src->stack.context, dst->stack.context ); 131 // when CtxSwitch returns we are back in the src coroutine 132 133 // set state of new coroutine to active 134 src->state = Active; 135 136 enable_interrupts( __cfaabi_dbg_ctx ); 137 verify( TL_GET( preemption_state.enabled ) || TL_GET( this_processor )->do_terminate ); 138 139 140 if( unlikely(src->cancellation != NULL) ) { 141 _CtxCoroutine_Unwind(src->cancellation, src); 142 } 143 } //ctxSwitchDirect 144 145 void create_stack( coStack_t* this, unsigned int storageSize ) with( *this ) { 146 //TEMP HACK do this on proper kernel startup 147 if(pageSize == 0ul) pageSize = sysconf( _SC_PAGESIZE ); 148 149 size_t cxtSize = libCeiling( sizeof(machine_context_t), 8 ); // minimum alignment 150 151 if ( !storage ) { 152 __cfaabi_dbg_print_safe("Kernel : Creating stack of size %zu for stack obj %p\n", cxtSize + size + 8, this); 153 154 userStack = false; 155 size = libCeiling( storageSize, 16 ); 156 // use malloc/memalign because "new" raises an exception for out-of-memory 157 158 // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment 159 __cfaabi_dbg_debug_do( storage = memalign( pageSize, cxtSize + size + pageSize ) ); 160 __cfaabi_dbg_no_debug_do( storage = malloc( cxtSize + size + 8 ) ); 161 162 __cfaabi_dbg_debug_do( 163 if ( mprotect( storage, pageSize, PROT_NONE ) == -1 ) { 164 abort( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) ); 165 } // if 166 ); 167 168 if ( (intptr_t)storage == 0 ) { 169 abort( "Attempt to allocate %zd bytes of storage for coroutine or task execution-state but insufficient memory available.", size ); 170 } // if 171 172 __cfaabi_dbg_debug_do( limit = (char *)storage + pageSize ); 173 __cfaabi_dbg_no_debug_do( limit = (char *)libCeiling( (unsigned long)storage, 16 ) ); // minimum alignment 174 175 } else { 176 __cfaabi_dbg_print_safe("Kernel : stack obj %p using user stack %p(%u bytes)\n", this, storage, storageSize); 177 178 assertf( ((size_t)storage & (libAlign() - 1)) == 0ul, "Stack storage %p for task/coroutine must be aligned on %d byte boundary.", storage, (int)libAlign() ); 179 userStack = true; 180 size = storageSize - cxtSize; 181 182 if ( size % 16 != 0u ) size -= 8; 183 184 limit = (char *)libCeiling( (unsigned long)storage, 16 ); // minimum alignment 185 } // if 186 assertf( size >= MinStackSize, "Stack size %zd provides less than minimum of %d bytes for a stack.", size, MinStackSize ); 187 188 base = (char *)limit + size; 189 context = base; 190 top = (char *)context + cxtSize; 125 // Safety note : Preemption must be disabled since there is a race condition 126 // kernelTLS.this_thread->curr_cor and $rsp/$rbp must agree at all times 127 verify( TL_GET( preemption_state.enabled ) || TL_GET( this_processor )->do_terminate ); 128 disable_interrupts(); 129 130 // set state of current coroutine to inactive 131 src->state = src->state == Halted ? Halted : Inactive; 132 133 // set new coroutine that task is executing 134 TL_GET( this_thread )->curr_cor = dst; 135 136 // context switch to specified coroutine 137 CtxSwitch( &src->context, &dst->context ); 138 // when CtxSwitch returns we are back in the src coroutine 139 140 // set state of new coroutine to active 141 src->state = Active; 142 143 enable_interrupts( __cfaabi_dbg_ctx ); 144 verify( TL_GET( preemption_state.enabled ) || TL_GET( this_processor )->do_terminate ); 145 146 if( unlikely(src->cancellation != NULL) ) { 147 _CtxCoroutine_Unwind(src->cancellation, src); 148 } 149 } 150 151 [void *, size_t] __stack_alloc( size_t storageSize ) { 152 static const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment 153 assert(__page_size != 0l); 154 size_t size = libCeiling( storageSize, 16 ) + stack_data_size; 155 156 // If we are running debug, we also need to allocate a guardpage to catch stack overflows. 157 void * storage; 158 __cfaabi_dbg_debug_do( 159 storage = memalign( __page_size, size + __page_size ); 160 ); 161 __cfaabi_dbg_no_debug_do( 162 storage = (void*)malloc(size); 163 ); 164 165 __cfaabi_dbg_print_safe("Kernel : Created stack %p of size %zu\n", storage, size); 166 __cfaabi_dbg_debug_do( 167 if ( mprotect( storage, __page_size, PROT_NONE ) == -1 ) { 168 abort( "__stack_alloc : internal error, mprotect failure, error(%d) %s.", (int)errno, strerror( (int)errno ) ); 169 } 170 storage = (void *)(((intptr_t)storage) + __page_size); 171 ); 172 173 verify( ((intptr_t)storage & (libAlign() - 1)) == 0ul ); 174 return [storage, size]; 175 } 176 177 void __stack_prepare( __stack_info_t * this, size_t create_size ) { 178 static const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment 179 bool userStack; 180 void * storage; 181 size_t size; 182 if ( !this->storage ) { 183 userStack = false; 184 [storage, size] = __stack_alloc( create_size ); 185 } else { 186 userStack = true; 187 __cfaabi_dbg_print_safe("Kernel : stack obj %p using user stack %p(%zu bytes)\n", this, this->storage, this->storage->size); 188 189 // The stack must be aligned, advance the pointer to the next align data 190 storage = (void*)libCeiling( (intptr_t)this->storage, libAlign()); 191 192 // The size needs to be shrinked to fit all the extra data structure and be aligned 193 ptrdiff_t diff = (intptr_t)storage - (intptr_t)this->storage; 194 size = libFloor(create_size - stack_data_size - diff, libAlign()); 195 } // if 196 assertf( size >= MinStackSize, "Stack size %zd provides less than minimum of %d bytes for a stack.", size, MinStackSize ); 197 198 this->storage = (__stack_t *)((intptr_t)storage + size); 199 this->storage->size = size; 200 this->storage->limit = storage; 201 this->storage->base = (void*)((intptr_t)storage + size); 202 this->userStack = userStack; 191 203 } 192 204 … … 194 206 // is not inline (We can't inline Cforall in C) 195 207 extern "C" { 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 208 void __suspend_internal(void) { 209 suspend(); 210 } 211 212 void __leave_coroutine( coroutine_desc * src ) { 213 coroutine_desc * starter = src->cancellation != 0 ? src->last : src->starter; 214 215 src->state = Halted; 216 217 assertf( starter != 0, 218 "Attempt to suspend/leave coroutine \"%.256s\" (%p) that has never been resumed.\n" 219 "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.", 220 src->name, src ); 221 assertf( starter->state != Halted, 222 "Attempt by coroutine \"%.256s\" (%p) to suspend/leave back to terminated coroutine \"%.256s\" (%p).\n" 223 "Possible cause is terminated coroutine's main routine has already returned.", 224 src->name, src, starter->name, starter ); 225 226 CoroutineCtxSwitch( src, starter ); 227 } 216 228 } 217 229 -
libcfa/src/concurrency/coroutine.hfa
r2fabdc02 rb2f6113 68 68 // Private wrappers for context switch and stack creation 69 69 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 70 extern void create_stack( coStack_t * this, unsigned int storageSize);70 extern void __stack_prepare ( __stack_info_t * this, size_t size /* ignored if storage already allocated */); 71 71 72 72 // Suspend implementation inlined for performance … … 102 102 coroutine_desc * dst = get_coroutine(cor); 103 103 104 if( unlikely(!dst->stack. base) ) {105 create_stack(&dst->stack, dst->stack.size);104 if( unlikely(!dst->stack.storage || !dst->stack.storage->base) ) { 105 __stack_prepare(&dst->stack, 65000); 106 106 CtxStart(&cor, CtxInvokeCoroutine); 107 107 } -
libcfa/src/concurrency/invoke.c
r2fabdc02 rb2f6113 122 122 void (*invoke)(void *) 123 123 ) { 124 struct coStack_t* stack = &get_coroutine( this )->stack; 124 struct coroutine_desc * cor = get_coroutine( this ); 125 struct __stack_t * stack = cor->stack.storage; 125 126 126 127 #if defined( __i386 ) … … 136 137 }; 137 138 138 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );139 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp139 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 140 cor->context.FP = NULL; // terminate stack with NULL fp 140 141 141 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; 142 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this; // argument to invoke 143 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 144 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 145 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 142 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 143 144 fs->dummyReturn = NULL; 145 fs->argument[0] = this; // argument to invoke 146 fs->rturn = invoke; 147 fs->mxcr = 0x1F80; //Vol. 2A 3-520 148 fs->fcw = 0x037F; //Vol. 1 8-7 146 149 147 150 #elif defined( __x86_64 ) … … 155 158 }; 156 159 157 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );158 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp160 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 161 cor->context.FP = NULL; // terminate stack with NULL fp 159 162 160 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; 161 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub; 162 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this; 163 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke; 164 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 165 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 163 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 164 165 fs->dummyReturn = NULL; 166 fs->rturn = CtxInvokeStub; 167 fs->fixedRegisters[0] = this; 168 fs->fixedRegisters[1] = invoke; 169 fs->mxcr = 0x1F80; //Vol. 2A 3-520 170 fs->fcw = 0x037F; //Vol. 1 8-7 166 171 167 172 #elif defined( __ARM_ARCH ) … … 173 178 }; 174 179 175 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );176 ((struct machine_context_t *)stack->context)->FP = NULL;180 cor->context.SP = (char *)stack->base - sizeof( struct FakeStack ); 181 cor->context.FP = NULL; 177 182 178 struct FakeStack *fs = (struct FakeStack *) ((struct machine_context_t *)stack->context)->SP;183 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 179 184 180 185 fs->intRegs[8] = CtxInvokeStub; -
libcfa/src/concurrency/invoke.h
r2fabdc02 rb2f6113 62 62 #endif 63 63 64 struct coStack_t { 65 size_t size; // size of stack 66 void * storage; // pointer to stack 67 void * limit; // stack grows towards stack limit 68 void * base; // base of stack 69 void * context; // address of cfa_context_t 70 void * top; // address of top of storage 71 bool userStack; // whether or not the user allocated the stack 64 struct __stack_context_t { 65 void * SP; 66 67 void * FP; 68 // copy of global UNIX variable errno 69 int errno_; 70 }; 71 72 // low adresses : +----------------------+ <- start of allocation 73 // | optional guard page | 74 // +----------------------+ <- __stack_t.limit 75 // | | 76 // | /\ /\ /\ | 77 // | || || || | 78 // | | 79 // | program stack | 80 // | | 81 // __stack_info_t.storage -> +----------------------+ <- __stack_t.base 82 // | __stack_t | 83 // high adresses : +----------------------+ <- end of allocation 84 85 struct __stack_t { 86 // size of stack 87 size_t size; 88 89 // stack grows towards stack limit 90 void * limit; 91 92 // base of stack 93 void * base; 94 }; 95 96 struct __stack_info_t { 97 // pointer to stack 98 struct __stack_t * storage; 99 100 // whether or not the user allocated the stack 101 bool userStack; 72 102 }; 73 103 … … 75 105 76 106 struct coroutine_desc { 107 // context that is switch during a CtxSwitch 108 struct __stack_context_t context; 109 77 110 // stack information of the coroutine 78 struct coStack_t stack;111 struct __stack_info_t stack; 79 112 80 113 // textual name for coroutine/task, initialized by uC++ generated code 81 114 const char * name; 82 115 83 // copy of global UNIX variable errno84 int errno_;85 86 116 // current execution status for coroutine 87 117 enum coroutine_state state; 118 88 119 // first coroutine to resume this one 89 120 struct coroutine_desc * starter; … … 230 261 // assembler routines that performs the context switch 231 262 extern void CtxInvokeStub( void ); 232 void CtxSwitch( void * from, void* to ) asm ("CtxSwitch");263 void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch"); 233 264 // void CtxStore ( void * this ) asm ("CtxStore"); 234 265 // void CtxRet ( void * dst ) asm ("CtxRet"); -
libcfa/src/concurrency/kernel.cfa
r2fabdc02 rb2f6113 42 42 //----------------------------------------------------------------------------- 43 43 // Kernel storage 44 KERNEL_STORAGE(cluster, 45 KERNEL_STORAGE(processor, 46 KERNEL_STORAGE(thread_desc, 47 KERNEL_STORAGE( machine_context_t,mainThreadCtx);44 KERNEL_STORAGE(cluster, mainCluster); 45 KERNEL_STORAGE(processor, mainProcessor); 46 KERNEL_STORAGE(thread_desc, mainThread); 47 KERNEL_STORAGE(__stack_t, mainThreadCtx); 48 48 49 49 cluster * mainCluster; … … 54 54 struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters; 55 55 } 56 57 size_t __page_size = 0; 56 58 57 59 //----------------------------------------------------------------------------- … … 66 68 // Struct to steal stack 67 69 struct current_stack_info_t { 68 machine_context_t ctx;70 __stack_t * storage; // pointer to stack object 69 71 unsigned int size; // size of stack 70 72 void *base; // base of stack 71 void *storage; // pointer to stack72 73 void *limit; // stack grows towards stack limit 73 74 void *context; // address of cfa_context_t 74 void *top; // address of top of storage75 75 }; 76 76 77 77 void ?{}( current_stack_info_t & this ) { 78 CtxGet( this.ctx );79 this.base = this.ctx.FP;80 this. storage = this.ctx.SP;78 __stack_context_t ctx; 79 CtxGet( ctx ); 80 this.base = ctx.FP; 81 81 82 82 rlimit r; … … 86 86 this.limit = (void *)(((intptr_t)this.base) - this.size); 87 87 this.context = &storage_mainThreadCtx; 88 this.top = this.base;89 88 } 90 89 91 90 //----------------------------------------------------------------------------- 92 91 // Main thread construction 93 void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {94 size = info->size;95 storage = info->storage;96 limit = info->limit;97 base = info->base;98 context = info->context;99 top = info->top;100 userStack = true;101 }102 92 103 93 void ?{}( coroutine_desc & this, current_stack_info_t * info) with( this ) { 104 stack{ info }; 94 context.errno_ = 0; 95 stack.storage = info->storage; 96 stack.userStack = true; 97 with(*stack.storage) { 98 size = info->size; 99 limit = info->limit; 100 base = info->base; 101 } 105 102 name = "Main Thread"; 106 errno_ = 0;107 103 state = Start; 108 104 starter = NULL; 105 last = NULL; 106 cancellation = NULL; 109 107 } 110 108 … … 312 310 // to waste the perfectly valid stack create by pthread. 313 311 current_stack_info_t info; 314 machine_context_t ctx;315 info. context= &ctx;312 __stack_t ctx; 313 info.storage = &ctx; 316 314 (proc->runner){ proc, &info }; 317 315 318 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack. base);316 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage); 319 317 320 318 //Set global state … … 353 351 verify( ! kernelTLS.preemption_state.enabled ); 354 352 355 create_stack(&dst->stack, dst->stack.size);353 __stack_prepare( &dst->stack, 65000 ); 356 354 CtxStart(&this->runner, CtxInvokeCoroutine); 357 355 … … 372 370 373 371 // context switch to specified coroutine 374 assert( src->stack.context ); 375 CtxSwitch( src->stack.context, dst->stack.context ); 372 CtxSwitch( &src->context, &dst->context ); 376 373 // when CtxSwitch returns we are back in the src coroutine 377 374 … … 545 542 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 546 543 544 __page_size = sysconf( _SC_PAGESIZE ); 545 547 546 __cfa_dbg_global_clusters.list{ __get }; 548 547 __cfa_dbg_global_clusters.lock{}; … … 559 558 mainThread = (thread_desc *)&storage_mainThread; 560 559 current_stack_info_t info; 560 info.storage = (__stack_t*)&storage_mainThreadCtx; 561 561 (*mainThread){ &info }; 562 562 -
libcfa/src/concurrency/thread.cfa
r2fabdc02 rb2f6113 80 80 81 81 disable_interrupts(); 82 create_stack(&thrd_c->stack, thrd_c->stack.size);82 assert( thrd_c->stack.storage ); 83 83 CtxStart(&this, CtxInvokeThread); 84 assert( thrd_c->last->stack.context ); 85 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); 84 CtxSwitch( &thrd_c->last->context, &thrd_c->context ); 86 85 87 86 ScheduleThread(thrd_h); … … 118 117 // set new coroutine that the processor is executing 119 118 // and context switch to it 120 assert( src->stack.context ); 121 CtxSwitch( src->stack.context, dst->stack.context ); 119 CtxSwitch( &src->context, &dst->context ); 122 120 123 121 // set state of new coroutine to active -
libcfa/src/concurrency/thread.hfa
r2fabdc02 rb2f6113 61 61 void ^?{}(thread_desc & this); 62 62 63 static inline void ?{}(thread_desc & this) { this{ "Anonymous Thread", *mainCluster, NULL, 0 }; }63 static inline void ?{}(thread_desc & this) { this{ "Anonymous Thread", *mainCluster, NULL, 65000 }; } 64 64 static inline void ?{}(thread_desc & this, size_t stackSize ) { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; } 65 65 static inline void ?{}(thread_desc & this, void * storage, size_t storageSize ) { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; } 66 static inline void ?{}(thread_desc & this, struct cluster & cl ) { this{ "Anonymous Thread", cl, NULL, 0 }; }67 static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize ) { this{ "Anonymous Thread", cl, 0, stackSize }; }66 static inline void ?{}(thread_desc & this, struct cluster & cl ) { this{ "Anonymous Thread", cl, NULL, 65000 }; } 67 static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize ) { this{ "Anonymous Thread", cl, NULL, stackSize }; } 68 68 static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize ) { this{ "Anonymous Thread", cl, storage, storageSize }; } 69 static inline void ?{}(thread_desc & this, const char * const name) { this{ name, *mainCluster, NULL, 0 }; }70 static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl ) { this{ name, cl, NULL, 0 }; }69 static inline void ?{}(thread_desc & this, const char * const name) { this{ name, *mainCluster, NULL, 65000 }; } 70 static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl ) { this{ name, cl, NULL, 65000 }; } 71 71 static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; } 72 72
Note: See TracChangeset
for help on using the changeset viewer.