- Timestamp:
- Mar 17, 2017, 11:34:15 AM (8 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:
- b32ada31
- Parents:
- 9f1695b
- Location:
- src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/CorCtxSwitch.c
r9f1695b r17af7d1 24 24 25 25 struct GreatSuspender { 26 coroutine_desc c;26 coroutine_desc __cor; 27 27 }; 28 28 -
src/benchmark/bench.c
r9f1695b r17af7d1 86 86 //======================================= 87 87 88 struct CoroutineDummy { coroutine_desc c; };88 struct CoroutineDummy { coroutine_desc __cor; }; 89 89 DECL_COROUTINE(CoroutineDummy); 90 90 void main(CoroutineDummy * this) {} … … 119 119 struct CoroutineResume { 120 120 int N; 121 coroutine_desc c;121 coroutine_desc __cor; 122 122 }; 123 123 … … 150 150 //======================================= 151 151 152 struct ThreadDummy { thread_desc t; };152 struct ThreadDummy { thread_desc __thrd; }; 153 153 DECL_THREAD(ThreadDummy); 154 154 void main(ThreadDummy * this) {} … … 180 180 int N; 181 181 long long result; 182 thread_desc t;182 thread_desc __thrd; 183 183 }; 184 184 -
src/benchmark/csv-data.c
r9f1695b r17af7d1 26 26 27 27 struct GreatSuspender { 28 coroutine_desc c;28 coroutine_desc __cor; 29 29 }; 30 30 -
src/examples/multicore.c
r9f1695b r17af7d1 2 2 #include <thread> 3 3 4 struct MyThread { thread_desc t; };4 struct MyThread { thread_desc __thrd; }; 5 5 6 6 DECL_THREAD(MyThread); -
src/libcfa/concurrency/coroutine
r9f1695b r17af7d1 30 30 }; 31 31 32 #define DECL_COROUTINE(X) static inline coroutine_desc* 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->__cor; } void main(X* this) 33 33 34 34 //----------------------------------------------------------------------------- -
src/libcfa/concurrency/invoke.c
r9f1695b r17af7d1 64 64 65 65 struct thread_desc* thrd = get_thread( this ); 66 struct coroutine_desc* cor = &thrd->c ;66 struct coroutine_desc* cor = &thrd->cor; 67 67 cor->state = Active; 68 68 … … 92 92 struct FakeStack { 93 93 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 94 uint32_t mxcr; 95 uint16_t fcw;// X97 FPU control word (preserved across function calls)96 void *rturn; 94 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 95 uint16_t fcw; // X97 FPU control word (preserved across function calls) 96 void *rturn; // where to go on return from uSwitch 97 97 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke 98 98 void *argument[3]; // for 16-byte ABI, 16-byte alignment starts here … … 106 106 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this; // argument to invoke 107 107 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 108 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 109 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 108 110 109 111 #elif defined( __x86_64__ ) 110 112 111 113 struct FakeStack { 112 void *fixedRegisters[5]; 113 uint32_t mxcr; 114 uint16_t fcw; 115 void *rturn; 116 void *dummyReturn; 114 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15 115 uint32_t mxcr; // SSE Status and Control bits (control bits are preserved across function calls) 116 uint16_t fcw; // X97 FPU control word (preserved across function calls) 117 void *rturn; // where to go on return from uSwitch 118 void *dummyReturn; // NULL return address to provide proper alignment 117 119 }; 118 120 -
src/libcfa/concurrency/invoke.h
r9f1695b r17af7d1 28 28 #define unlikely(x) __builtin_expect(!!(x), 0) 29 29 #define thread_local _Thread_local 30 #define SCHEDULER_CAPACITY 1031 30 32 31 struct spinlock { … … 60 59 61 60 struct coStack_t { 62 unsigned int size; 63 void *storage; 64 void *limit; 65 void *base; 66 void *context; 67 void *top; 68 bool userStack; 61 unsigned int size; // size of stack 62 void *storage; // pointer to stack 63 void *limit; // stack grows towards stack limit 64 void *base; // base of stack 65 void *context; // address of cfa_context_t 66 void *top; // address of top of storage 67 bool userStack; // whether or not the user allocated the stack 69 68 }; 70 69 … … 72 71 73 72 struct coroutine_desc { 74 struct coStack_t stack; 75 const char *name; 76 int errno_; 77 enum coroutine_state state; 78 struct coroutine_desc *starter; 79 struct coroutine_desc *last; 73 struct coStack_t stack; // stack information of the coroutine 74 const char *name; // textual name for coroutine/task, initialized by uC++ generated code 75 int errno_; // copy of global UNIX variable errno 76 enum coroutine_state state; // current execution status for coroutine 77 struct coroutine_desc *starter; // first coroutine to resume this one 78 struct coroutine_desc *last; // last coroutine to resume this one 80 79 }; 81 80 82 81 struct thread_desc { 83 struct coroutine_desc c ;// coroutine body used to store context82 struct coroutine_desc cor; // coroutine body used to store context 84 83 struct signal_once terminated; // indicate if execuation state is not halted 85 struct thread_desc * next; 84 struct thread_desc * next; // instrusive link field for threads 86 85 }; 87 86 -
src/libcfa/concurrency/kernel.c
r9f1695b r17af7d1 107 107 108 108 void ?{}( thread_desc * this, current_stack_info_t * info) { 109 (&this->c ){ info };109 (&this->cor){ info }; 110 110 } 111 111 … … 113 113 // Processor coroutine 114 114 void ?{}(processorCtx_t * this, processor * proc) { 115 (&this-> c){};115 (&this->__cor){}; 116 116 this->proc = proc; 117 117 proc->runner = this; … … 119 119 120 120 void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) { 121 (&this-> c){ info };121 (&this->__cor){ info }; 122 122 this->proc = proc; 123 123 proc->runner = this; … … 255 255 processorCtx_t proc_cor_storage = { proc, &info }; 256 256 257 LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage. c.stack.base);257 LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 258 258 259 259 //Set global state 260 proc->current_coroutine = &proc->runner-> c;260 proc->current_coroutine = &proc->runner->__cor; 261 261 proc->current_thread = NULL; 262 262 … … 268 268 // back to here. Instead directly call the main since we already are on the 269 269 // appropriate stack. 270 proc_cor_storage. c.state = Active;270 proc_cor_storage.__cor.state = Active; 271 271 main( &proc_cor_storage ); 272 proc_cor_storage. c.state = Halted;272 proc_cor_storage.__cor.state = Halted; 273 273 274 274 // Main routine of the core returned, the core is now fully terminated … … 359 359 this_processor = systemProcessor; 360 360 this_processor->current_thread = mainThread; 361 this_processor->current_coroutine = &mainThread->c ;361 this_processor->current_coroutine = &mainThread->cor; 362 362 363 363 // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX -
src/libcfa/concurrency/kernel_private.h
r9f1695b r17af7d1 35 35 struct processorCtx_t { 36 36 processor * proc; 37 coroutine_desc c;37 coroutine_desc __cor; 38 38 }; 39 39 -
src/libcfa/concurrency/monitor
r9f1695b r17af7d1 34 34 } 35 35 36 //Basic entering routine37 void enter(monitor_desc *);38 void leave(monitor_desc *);39 40 36 //Array entering routine 41 37 void enter(monitor_desc **, int count); … … 49 45 static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) { 50 46 return ((intptr_t)lhs) < ((intptr_t)rhs); 51 }52 53 static inline void ?{}( monitor_guard_t * this, monitor_desc ** m ) {54 this->m = m;55 this->count = 1;56 enter( *this->m );57 47 } 58 48 -
src/libcfa/concurrency/monitor.c
r9f1695b r17af7d1 74 74 void enter(monitor_desc ** monitors, int count) { 75 75 for(int i = 0; i < count; i++) { 76 // printf("%d\n", i);77 76 enter( monitors[i] ); 78 77 } … … 81 80 void leave(monitor_desc ** monitors, int count) { 82 81 for(int i = count - 1; i >= 0; i--) { 83 // printf("%d\n", i);84 82 leave( monitors[i] ); 85 83 } -
src/libcfa/concurrency/thread
r9f1695b r17af7d1 33 33 }; 34 34 35 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this-> t; } void main(X* this)35 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this) 36 36 37 37 forall( dtype T | is_thread(T) ) 38 38 static inline coroutine_desc* get_coroutine(T* this) { 39 return &get_thread(this)->c ;39 return &get_thread(this)->cor; 40 40 } 41 41 42 42 static inline coroutine_desc* get_coroutine(thread_desc* this) { 43 return &this->c ;43 return &this->cor; 44 44 } 45 45 -
src/libcfa/concurrency/thread.c
r9f1695b r17af7d1 42 42 43 43 void ?{}(thread_desc* this) { 44 (&this->c ){};45 this->c .name = "Anonymous Coroutine";44 (&this->cor){}; 45 this->cor.name = "Anonymous Coroutine"; 46 46 (&this->terminated){}; 47 47 this->next = NULL; … … 49 49 50 50 void ^?{}(thread_desc* this) { 51 ^(&this->c ){};51 ^(&this->cor){}; 52 52 } 53 53 … … 120 120 extern "C" { 121 121 void __thread_signal_termination( thread_desc * this ) { 122 this->c .state = Halted;122 this->cor.state = Halted; 123 123 LIB_DEBUG_PRINTF("Thread end : %p\n", this); 124 124 signal( &this->terminated ); -
src/tests/coroutine.c
r9f1695b r17af7d1 4 4 struct Fibonacci { 5 5 int fn; // used for communication 6 coroutine_desc c;6 coroutine_desc __cor; 7 7 }; 8 8 … … 12 12 13 13 coroutine_desc* get_coroutine(Fibonacci* this) { 14 return &this-> c;14 return &this->__cor; 15 15 } 16 16 … … 18 18 #ifdef MORE_DEBUG 19 19 sout | "Starting main of coroutine " | this | endl; 20 sout | "Started from " | this-> c.last | endl;20 sout | "Started from " | this->__cor.last | endl; 21 21 #endif 22 22 int fn1, fn2; // retained between resumes -
src/tests/monitor.c
r9f1695b r17af7d1 31 31 } 32 32 33 struct MyThread { thread_desc t; };33 struct MyThread { thread_desc __thrd; }; 34 34 35 35 DECL_THREAD(MyThread); -
src/tests/multi-monitor.c
r9f1695b r17af7d1 21 21 22 22 struct MyThread { 23 thread_desc t;23 thread_desc __thrd; 24 24 int target; 25 25 }; -
src/tests/thread.c
r9f1695b r17af7d1 4 4 #include <thread> 5 5 6 struct First { thread_desc t; signal_once* lock; };7 struct Second { thread_desc t; signal_once* lock; };6 struct First { thread_desc __thrd; signal_once* lock; }; 7 struct Second { thread_desc __thrd; signal_once* lock; }; 8 8 9 9 DECL_THREAD(First);
Note: See TracChangeset
for help on using the changeset viewer.