Changeset 6b224a52 for src/libcfa/concurrency
- Timestamp:
- Aug 25, 2017, 12:11:53 PM (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:
- bf7b9da7
- Parents:
- 135b431 (diff), f676b84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/libcfa/concurrency
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r135b431 r6b224a52 40 40 __cfa_time_t zero_time = { 0 }; 41 41 42 void ?{}( __cfa_time_t * this ) { this->val = 0; }43 void ?{}( __cfa_time_t * this, zero_t zero ) { this->val = 0; }44 45 void ?{}( itimerval *this, __cfa_time_t * alarm ) {46 this ->it_value.tv_sec = alarm->val / one_second; // seconds47 this ->it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds48 this ->it_interval.tv_sec = 0;49 this ->it_interval.tv_usec = 0;50 } 51 52 53 void ?{}( __cfa_time_t *this, timespec * curr ) {42 void ?{}( __cfa_time_t & this ) { this.val = 0; } 43 void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; } 44 45 void ?{}( itimerval & this, __cfa_time_t * alarm ) { 46 this.it_value.tv_sec = alarm->val / one_second; // seconds 47 this.it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds 48 this.it_interval.tv_sec = 0; 49 this.it_interval.tv_usec = 0; 50 } 51 52 53 void ?{}( __cfa_time_t & this, timespec * curr ) { 54 54 uint64_t secs = curr->tv_sec; 55 55 uint64_t nsecs = curr->tv_nsec; 56 this ->val = (secs * one_second) + nsecs;57 } 58 59 __cfa_time_t ?=?( __cfa_time_t *this, zero_t rhs ) {60 this ->val = 0;61 return *this;56 this.val = (secs * one_second) + nsecs; 57 } 58 59 __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) { 60 this.val = 0; 61 return this; 62 62 } 63 63 … … 86 86 //============================================================================================= 87 87 88 void ?{}( alarm_node_t *this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {89 this ->thrd = thrd;90 this ->alarm = alarm;91 this ->period = period;92 this ->next = 0;93 this ->set = false;94 this ->kernel_alarm = false;95 } 96 97 void ?{}( alarm_node_t *this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {98 this ->proc = proc;99 this ->alarm = alarm;100 this ->period = period;101 this ->next = 0;102 this ->set = false;103 this ->kernel_alarm = true;104 } 105 106 void ^?{}( alarm_node_t *this ) {107 if( this ->set ) {108 unregister_self( this );88 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) { 89 this.thrd = thrd; 90 this.alarm = alarm; 91 this.period = period; 92 this.next = 0; 93 this.set = false; 94 this.kernel_alarm = false; 95 } 96 97 void ?{}( alarm_node_t & this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) { 98 this.proc = proc; 99 this.alarm = alarm; 100 this.period = period; 101 this.next = 0; 102 this.set = false; 103 this.kernel_alarm = true; 104 } 105 106 void ^?{}( alarm_node_t & this ) { 107 if( this.set ) { 108 unregister_self( &this ); 109 109 } 110 110 } -
src/libcfa/concurrency/alarm.h
r135b431 r6b224a52 36 36 37 37 // ctors 38 void ?{}( __cfa_time_t *this );39 void ?{}( __cfa_time_t *this, zero_t zero );40 void ?{}( __cfa_time_t *this, timespec * curr );41 void ?{}( itimerval *this, __cfa_time_t * alarm );38 void ?{}( __cfa_time_t & this ); 39 void ?{}( __cfa_time_t & this, zero_t zero ); 40 void ?{}( __cfa_time_t & this, timespec * curr ); 41 void ?{}( itimerval & this, __cfa_time_t * alarm ); 42 42 43 __cfa_time_t ?=?( __cfa_time_t *this, zero_t rhs );43 __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ); 44 44 45 45 // logical ops … … 105 105 typedef alarm_node_t ** __alarm_it_t; 106 106 107 void ?{}( alarm_node_t *this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );108 void ?{}( alarm_node_t *this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );109 void ^?{}( alarm_node_t *this );107 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ); 108 void ?{}( alarm_node_t & this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ); 109 void ^?{}( alarm_node_t & this ); 110 110 111 111 struct alarm_list_t { … … 114 114 }; 115 115 116 static inline void ?{}( alarm_list_t *this ) {117 this ->head = 0;118 this ->tail = &this->head;116 static inline void ?{}( alarm_list_t & this ) { 117 this.head = 0; 118 this.tail = &this.head; 119 119 } 120 120 -
src/libcfa/concurrency/coroutine
r135b431 r6b224a52 25 25 // Anything that is resumed is a coroutine. 26 26 trait is_coroutine(dtype T) { 27 void main(T *this);28 coroutine_desc * get_coroutine(T *this);27 void main(T & this); 28 coroutine_desc * get_coroutine(T & this); 29 29 }; 30 30 31 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X * this) { return &this->__cor; } void main(X*this)31 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this) 32 32 33 33 //----------------------------------------------------------------------------- 34 34 // 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);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); 40 40 41 41 //----------------------------------------------------------------------------- … … 44 44 45 45 forall(dtype T | is_coroutine(T)) 46 static inline void resume(T *cor);46 static inline void resume(T & cor); 47 47 48 48 forall(dtype T | is_coroutine(T)) 49 void prime(T *cor);49 void prime(T & cor); 50 50 51 51 //----------------------------------------------------------------------------- … … 86 86 // Resume implementation inlined for performance 87 87 forall(dtype T | is_coroutine(T)) 88 static inline void resume(T *cor) {88 static inline void resume(T & cor) { 89 89 coroutine_desc * src = this_coroutine; // optimization 90 90 coroutine_desc * dst = get_coroutine(cor); … … 92 92 if( unlikely(!dst->stack.base) ) { 93 93 create_stack(&dst->stack, dst->stack.size); 94 CtxStart( cor, CtxInvokeCoroutine);94 CtxStart(&cor, CtxInvokeCoroutine); 95 95 } 96 96 -
src/libcfa/concurrency/coroutine.c
r135b431 r6b224a52 40 40 //----------------------------------------------------------------------------- 41 41 // Coroutine ctors and dtors 42 void ?{}(coStack_t *this) {43 this ->size = 65000; // size of stack44 this ->storage = NULL; // pointer to stack45 this ->limit = NULL; // stack grows towards stack limit46 this ->base = NULL; // base of stack47 this ->context = NULL; // address of cfa_context_t48 this ->top = NULL; // address of top of storage49 this ->userStack = false;42 void ?{}(coStack_t& this) { 43 this.size = 65000; // size of stack 44 this.storage = NULL; // pointer to stack 45 this.limit = NULL; // stack grows towards stack limit 46 this.base = NULL; // base of stack 47 this.context = NULL; // address of cfa_context_t 48 this.top = NULL; // address of top of storage 49 this.userStack = false; 50 50 } 51 51 52 void ?{}(coStack_t *this, size_t size) {52 void ?{}(coStack_t& this, size_t size) { 53 53 this{}; 54 this ->size = size;54 this.size = size; 55 55 56 create_stack( this, this->size);56 create_stack(&this, this.size); 57 57 } 58 58 59 void ?{}(coroutine_desc *this) {59 void ?{}(coroutine_desc& this) { 60 60 this{ "Anonymous Coroutine" }; 61 61 } 62 62 63 void ?{}(coroutine_desc *this, const char * name) {64 this ->name = name;65 this ->errno_ = 0;66 this ->state = Start;67 this ->starter = NULL;68 this ->last = NULL;63 void ?{}(coroutine_desc& this, const char * name) { 64 this.name = name; 65 this.errno_ = 0; 66 this.state = Start; 67 this.starter = NULL; 68 this.last = NULL; 69 69 } 70 70 71 void ?{}(coroutine_desc *this, size_t size) {71 void ?{}(coroutine_desc& this, size_t size) { 72 72 this{}; 73 ( &this->stack){size};73 (this.stack){size}; 74 74 } 75 75 76 void ^?{}(coStack_t *this) {77 if ( ! this ->userStack ) {76 void ^?{}(coStack_t& this) { 77 if ( ! this.userStack ) { 78 78 LIB_DEBUG_DO( 79 if ( mprotect( this ->storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {80 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", this, errno, strerror( errno ) );79 if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) { 80 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 81 81 } 82 82 ); 83 free( this ->storage );83 free( this.storage ); 84 84 } 85 85 } 86 86 87 void ^?{}(coroutine_desc *this) {}87 void ^?{}(coroutine_desc& this) {} 88 88 89 89 // Part of the Public API 90 90 // Not inline since only ever called once per coroutine 91 91 forall(dtype T | is_coroutine(T)) 92 void prime(T *cor) {92 void prime(T& cor) { 93 93 coroutine_desc* this = get_coroutine(cor); 94 94 assert(this->state == Start); -
src/libcfa/concurrency/invoke.h
r135b431 r6b224a52 49 49 #ifdef __CFORALL__ 50 50 extern "Cforall" { 51 void ?{}( struct __thread_queue_t *);51 void ?{}( struct __thread_queue_t & ); 52 52 void append( struct __thread_queue_t *, struct thread_desc * ); 53 53 struct thread_desc * pop_head( struct __thread_queue_t * ); 54 54 struct thread_desc * remove( struct __thread_queue_t *, struct thread_desc ** ); 55 55 56 void ?{}( struct __condition_stack_t *);56 void ?{}( struct __condition_stack_t & ); 57 57 void push( struct __condition_stack_t *, struct __condition_criterion_t * ); 58 58 struct __condition_criterion_t * pop( struct __condition_stack_t * ); 59 59 60 void ?{}(spinlock *this);61 void ^?{}(spinlock *this);60 void ?{}(spinlock & this); 61 void ^?{}(spinlock & this); 62 62 } 63 63 #endif -
src/libcfa/concurrency/kernel
r135b431 r6b224a52 37 37 }; 38 38 39 void ?{}(semaphore *this, int count = 1);40 void ^?{}(semaphore *this);39 void ?{}(semaphore & this, int count = 1); 40 void ^?{}(semaphore & this); 41 41 void P(semaphore * this); 42 42 void V(semaphore * this); … … 51 51 }; 52 52 53 void ?{}(cluster *this);54 void ^?{}(cluster *this);53 void ?{}(cluster & this); 54 void ^?{}(cluster & this); 55 55 56 56 //----------------------------------------------------------------------------- … … 68 68 unsigned short thrd_count; 69 69 }; 70 static inline void ?{}(FinishAction *this) {71 this ->action_code = No_Action;72 this ->thrd = NULL;73 this ->lock = NULL;70 static inline void ?{}(FinishAction & this) { 71 this.action_code = No_Action; 72 this.thrd = NULL; 73 this.lock = NULL; 74 74 } 75 static inline void ^?{}(FinishAction *this) {}75 static inline void ^?{}(FinishAction & this) {} 76 76 77 77 // Processor … … 99 99 }; 100 100 101 void ?{}(processor *this);102 void ?{}(processor *this, cluster * cltr);103 void ^?{}(processor *this);101 void ?{}(processor & this); 102 void ?{}(processor & this, cluster * cltr); 103 void ^?{}(processor & this); 104 104 105 105 // Local Variables: // -
src/libcfa/concurrency/kernel.c
r135b431 r6b224a52 73 73 }; 74 74 75 void ?{}( current_stack_info_t *this ) {76 CtxGet( this ->ctx );77 this ->base = this->ctx.FP;78 this ->storage = this->ctx.SP;75 void ?{}( current_stack_info_t & this ) { 76 CtxGet( this.ctx ); 77 this.base = this.ctx.FP; 78 this.storage = this.ctx.SP; 79 79 80 80 rlimit r; 81 81 getrlimit( RLIMIT_STACK, &r); 82 this ->size = r.rlim_cur;83 84 this ->limit = (void *)(((intptr_t)this->base) - this->size);85 this ->context = &storage_mainThreadCtx;86 this ->top = this->base;87 } 88 89 void ?{}( coStack_t *this, current_stack_info_t * info) {90 this ->size = info->size;91 this ->storage = info->storage;92 this ->limit = info->limit;93 this ->base = info->base;94 this ->context = info->context;95 this ->top = info->top;96 this ->userStack = true;97 } 98 99 void ?{}( coroutine_desc *this, current_stack_info_t * info) {100 ( &this->stack){ info };101 this ->name = "Main Thread";102 this ->errno_ = 0;103 this ->state = Start;104 } 105 106 void ?{}( thread_desc *this, current_stack_info_t * info) {107 ( &this->cor){ info };82 this.size = r.rlim_cur; 83 84 this.limit = (void *)(((intptr_t)this.base) - this.size); 85 this.context = &storage_mainThreadCtx; 86 this.top = this.base; 87 } 88 89 void ?{}( coStack_t & this, current_stack_info_t * info) { 90 this.size = info->size; 91 this.storage = info->storage; 92 this.limit = info->limit; 93 this.base = info->base; 94 this.context = info->context; 95 this.top = info->top; 96 this.userStack = true; 97 } 98 99 void ?{}( coroutine_desc & this, current_stack_info_t * info) { 100 (this.stack){ info }; 101 this.name = "Main Thread"; 102 this.errno_ = 0; 103 this.state = Start; 104 } 105 106 void ?{}( thread_desc & this, current_stack_info_t * info) { 107 (this.cor){ info }; 108 108 } 109 109 110 110 //----------------------------------------------------------------------------- 111 111 // Processor coroutine 112 void ?{}(processorCtx_t *this, processor * proc) {113 ( &this->__cor){ "Processor" };114 this ->proc = proc;115 proc->runner = this;116 } 117 118 void ?{}(processorCtx_t *this, processor * proc, current_stack_info_t * info) {119 ( &this->__cor){ info };120 this ->proc = proc;121 proc->runner = this;122 } 123 124 void ?{}(processor *this) {112 void ?{}(processorCtx_t & this, processor * proc) { 113 (this.__cor){ "Processor" }; 114 this.proc = proc; 115 proc->runner = &this; 116 } 117 118 void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) { 119 (this.__cor){ info }; 120 this.proc = proc; 121 proc->runner = &this; 122 } 123 124 void ?{}(processor & this) { 125 125 this{ mainCluster }; 126 126 } 127 127 128 void ?{}(processor *this, cluster * cltr) {129 this ->cltr = cltr;130 ( &this->terminated){ 0 };131 this ->do_terminate = false;132 this ->preemption_alarm = NULL;133 this ->pending_preemption = false;134 135 start( this );136 } 137 138 void ?{}(processor * this, cluster * cltr, processorCtx_t *runner) {139 this ->cltr = cltr;140 ( &this->terminated){ 0 };141 this ->do_terminate = false;142 this ->preemption_alarm = NULL;143 this ->pending_preemption = false;144 this ->kernel_thread = pthread_self();145 146 this ->runner =runner;147 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", runner);148 runner{ this };149 } 150 151 void ^?{}(processor *this) {152 if( ! this ->do_terminate ) {153 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this);154 this ->do_terminate = true;155 P( &this ->terminated );156 pthread_join( this ->kernel_thread, NULL );157 } 158 } 159 160 void ?{}(cluster *this) {161 ( &this->ready_queue ){};162 ( &this->ready_queue_lock ){};163 164 this ->preemption = default_preemption();165 } 166 167 void ^?{}(cluster *this) {128 void ?{}(processor & this, cluster * cltr) { 129 this.cltr = cltr; 130 (this.terminated){ 0 }; 131 this.do_terminate = false; 132 this.preemption_alarm = NULL; 133 this.pending_preemption = false; 134 135 start( &this ); 136 } 137 138 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) { 139 this.cltr = cltr; 140 (this.terminated){ 0 }; 141 this.do_terminate = false; 142 this.preemption_alarm = NULL; 143 this.pending_preemption = false; 144 this.kernel_thread = pthread_self(); 145 146 this.runner = &runner; 147 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner); 148 runner{ &this }; 149 } 150 151 void ^?{}(processor & this) { 152 if( ! this.do_terminate ) { 153 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this); 154 this.do_terminate = true; 155 P( &this.terminated ); 156 pthread_join( this.kernel_thread, NULL ); 157 } 158 } 159 160 void ?{}(cluster & this) { 161 ( this.ready_queue ){}; 162 ( this.ready_queue_lock ){}; 163 164 this.preemption = default_preemption(); 165 } 166 167 void ^?{}(cluster & this) { 168 168 169 169 } … … 173 173 //============================================================================================= 174 174 //Main of the processor contexts 175 void main(processorCtx_t *runner) {176 processor * this = runner ->proc;175 void main(processorCtx_t & runner) { 176 processor * this = runner.proc; 177 177 178 178 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); … … 219 219 // from the processor coroutine to the target thread 220 220 void runThread(processor * this, thread_desc * dst) { 221 coroutine_desc * proc_cor = get_coroutine( this->runner);221 coroutine_desc * proc_cor = get_coroutine(*this->runner); 222 222 coroutine_desc * thrd_cor = get_coroutine(dst); 223 223 … … 301 301 // appropriate stack. 302 302 proc_cor_storage.__cor.state = Active; 303 main( &proc_cor_storage );303 main( proc_cor_storage ); 304 304 proc_cor_storage.__cor.state = Halted; 305 305 … … 443 443 mainThread = (thread_desc *)&storage_mainThread; 444 444 current_stack_info_t info; 445 mainThread{ &info };445 (*mainThread){ &info }; 446 446 447 447 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); … … 449 449 // Initialize the main cluster 450 450 mainCluster = (cluster *)&storage_mainCluster; 451 mainCluster{};451 (*mainCluster){}; 452 452 453 453 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n"); … … 456 456 // (the coroutine that contains the processing control flow) 457 457 mainProcessor = (processor *)&storage_mainProcessor; 458 mainProcessor{ mainCluster,(processorCtx_t *)&storage_mainProcessorCtx };458 (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx }; 459 459 460 460 //initialize the global state variables … … 473 473 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 474 474 // mainThread is on the ready queue when this call is made. 475 resume( mainProcessor->runner );475 resume( *mainProcessor->runner ); 476 476 477 477 … … 501 501 // Destroy the main processor and its context in reverse order of construction 502 502 // These were manually constructed so we need manually destroy them 503 ^( mainProcessor->runner){};503 ^(*mainProcessor->runner){}; 504 504 ^(mainProcessor){}; 505 505 … … 569 569 //----------------------------------------------------------------------------- 570 570 // Locks 571 void ?{}( spinlock *this ) {572 this ->lock = 0;573 } 574 void ^?{}( spinlock *this ) {571 void ?{}( spinlock & this ) { 572 this.lock = 0; 573 } 574 void ^?{}( spinlock & this ) { 575 575 576 576 } … … 606 606 } 607 607 608 void ?{}( semaphore *this, int count = 1 ) {609 ( &this->lock){};610 this ->count = count;611 ( &this->waiting){};612 } 613 void ^?{}(semaphore *this) {}608 void ?{}( semaphore & this, int count = 1 ) { 609 (this.lock){}; 610 this.count = count; 611 (this.waiting){}; 612 } 613 void ^?{}(semaphore & this) {} 614 614 615 615 void P(semaphore * this) { … … 645 645 //----------------------------------------------------------------------------- 646 646 // Queues 647 void ?{}( __thread_queue_t *this ) {648 this ->head = NULL;649 this ->tail = &this->head;647 void ?{}( __thread_queue_t & this ) { 648 this.head = NULL; 649 this.tail = &this.head; 650 650 } 651 651 … … 685 685 } 686 686 687 688 689 void ?{}( __condition_stack_t * this ) { 690 this->top = NULL; 687 void ?{}( __condition_stack_t & this ) { 688 this.top = NULL; 691 689 } 692 690 -
src/libcfa/concurrency/monitor
r135b431 r6b224a52 22 22 #include "stdlib" 23 23 24 static inline void ?{}(monitor_desc *this) {25 ( &this->lock){};26 this ->owner = NULL;27 ( &this->entry_queue){};28 ( &this->signal_stack){};29 this ->recursion = 0;30 this ->acceptables = NULL;31 this ->acceptable_count = 0;32 this ->accepted_index = -1;24 static inline void ?{}(monitor_desc & this) { 25 (this.lock){}; 26 this.owner = NULL; 27 (this.entry_queue){}; 28 (this.signal_stack){}; 29 this.recursion = 0; 30 this.acceptables = NULL; 31 this.acceptable_count = 0; 32 this.accepted_index = -1; 33 33 } 34 34 … … 45 45 } 46 46 47 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)());48 void ^?{}( monitor_guard_t *this );47 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count ); 48 void ^?{}( monitor_guard_t & this ); 49 49 50 50 //----------------------------------------------------------------------------- … … 71 71 }; 72 72 73 void ?{}( __condition_blocked_queue_t *);73 void ?{}( __condition_blocked_queue_t & ); 74 74 void append( __condition_blocked_queue_t *, __condition_node_t * ); 75 75 __condition_node_t * pop_head( __condition_blocked_queue_t * ); … … 81 81 }; 82 82 83 static inline void ?{}( condition *this ) {84 this ->monitors = NULL;85 this ->monitor_count = 0;83 static inline void ?{}( condition & this ) { 84 this.monitors = NULL; 85 this.monitor_count = 0; 86 86 } 87 87 88 static inline void ^?{}( condition *this ) {89 free( this ->monitors );88 static inline void ^?{}( condition & this ) { 89 free( this.monitors ); 90 90 } 91 91 -
src/libcfa/concurrency/monitor.c
r135b431 r6b224a52 194 194 // Ctor for monitor guard 195 195 // Sorts monitors before entering 196 void ?{}( monitor_guard_t *this, monitor_desc ** m, int count, void (*func)() ) {196 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() ) { 197 197 // Store current array 198 this ->m = m;199 this ->count = count;198 this.m = m; 199 this.count = count; 200 200 201 201 // Sort monitors based on address -> TODO use a sort specialized for small numbers 202 qsort(this ->m, count);202 qsort(this.m, count); 203 203 204 204 // Save previous thread context 205 this ->prev_mntrs = this_thread->current_monitors;206 this ->prev_count = this_thread->current_monitor_count;207 this ->prev_func = this_thread->current_monitor_func;205 this.prev_mntrs = this_thread->current_monitors; 206 this.prev_count = this_thread->current_monitor_count; 207 this.prev_func = this_thread->current_monitor_func; 208 208 209 209 // Update thread context (needed for conditions) … … 213 213 214 214 // Enter the monitors in order 215 enter( this->m, this->count, func ); 216 } 215 enter( this.m, this.count, func ); 216 } 217 217 218 218 219 // Dtor for monitor guard 219 void ^?{}( monitor_guard_t *this ) {220 void ^?{}( monitor_guard_t & this ) { 220 221 // Leave the monitors in order 221 leave( this ->m, this->count );222 leave( this.m, this.count ); 222 223 223 224 // Restore thread context 224 this_thread->current_monitors = this ->prev_mntrs;225 this_thread->current_monitor_count = this ->prev_count;226 this_thread->current_monitor_func = this ->prev_func;225 this_thread->current_monitors = this.prev_mntrs; 226 this_thread->current_monitor_count = this.prev_count; 227 this_thread->current_monitor_func = this.prev_func; 227 228 } 228 229 229 230 //----------------------------------------------------------------------------- 230 231 // Internal scheduling types 231 232 void ?{}(__condition_node_t * this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) { 233 this->waiting_thread = waiting_thread; 234 this->count = count; 235 this->next = NULL; 236 this->user_info = user_info; 237 } 238 239 void ?{}(__condition_criterion_t * this ) { 240 this->ready = false; 241 this->target = NULL; 242 this->owner = NULL; 243 this->next = NULL; 244 } 245 246 void ?{}(__condition_criterion_t * this, monitor_desc * target, __condition_node_t * owner ) { 247 this->ready = false; 248 this->target = target; 249 this->owner = owner; 250 this->next = NULL; 232 void ?{}(__condition_node_t & this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) { 233 this.waiting_thread = waiting_thread; 234 this.count = count; 235 this.next = NULL; 236 this.user_info = user_info; 237 } 238 239 void ?{}(__condition_criterion_t & this ) { 240 this.ready = false; 241 this.target = NULL; 242 this.owner = NULL; 243 this.next = NULL; 244 } 245 246 void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner ) { 247 this.ready = false; 248 this.target = target; 249 this.owner = owner; 250 this.next = NULL; 251 251 } 252 252 … … 523 523 static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) { 524 524 for(int i = 0; i < count; i++) { 525 ( &criteria[i]){ monitors[i], waiter };525 (criteria[i]){ monitors[i], waiter }; 526 526 } 527 527 … … 531 531 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) { 532 532 for(int i = 0; i < count; i++) { 533 ( &criteria[i]){ monitors[i], waiter };533 (criteria[i]){ monitors[i], waiter }; 534 534 push( &criteria[i].target->signal_stack, &criteria[i] ); 535 535 } … … 627 627 return end + 1; 628 628 } 629 629 630 630 631 static inline bool match( __acceptable_t * acc, thread_desc * thrd ) { … … 660 661 return NULL; 661 662 } 662 663 void ?{}( __condition_blocked_queue_t * this ) { 664 this->head = NULL; 665 this->tail = &this->head; 663 void ?{}( __condition_blocked_queue_t & this ) { 664 this.head = NULL; 665 this.tail = &this.head; 666 666 } 667 667 -
src/libcfa/concurrency/preemption.c
r135b431 r6b224a52 71 71 static pthread_t alarm_thread; // pthread handle to alarm thread 72 72 73 void ?{}(event_kernel_t *this) {74 ( &this->alarms){};75 ( &this->lock){};73 void ?{}(event_kernel_t & this) { 74 (this.alarms){}; 75 (this.lock){}; 76 76 } 77 77 … … 240 240 // Initialize the event kernel 241 241 event_kernel = (event_kernel_t *)&storage_event_kernel; 242 event_kernel{};242 (*event_kernel){}; 243 243 244 244 // Setup proper signal handlers … … 276 276 // Raii ctor/dtor for the preemption_scope 277 277 // Used by thread to control when they want to receive preemption signals 278 void ?{}( preemption_scope *this, processor * proc ) {279 ( &this->alarm){ proc, zero_time, zero_time };280 this ->proc = proc;281 this ->proc->preemption_alarm = &this->alarm;282 283 update_preemption( this ->proc, from_us(this->proc->cltr->preemption) );284 } 285 286 void ^?{}( preemption_scope *this ) {278 void ?{}( preemption_scope & this, processor * proc ) { 279 (this.alarm){ proc, zero_time, zero_time }; 280 this.proc = proc; 281 this.proc->preemption_alarm = &this.alarm; 282 283 update_preemption( this.proc, from_us(this.proc->cltr->preemption) ); 284 } 285 286 void ^?{}( preemption_scope & this ) { 287 287 disable_interrupts(); 288 288 289 update_preemption( this ->proc, zero_time );289 update_preemption( this.proc, zero_time ); 290 290 } 291 291 -
src/libcfa/concurrency/preemption.h
r135b431 r6b224a52 30 30 }; 31 31 32 void ?{}( preemption_scope *this, processor * proc );33 void ^?{}( preemption_scope *this );32 void ?{}( preemption_scope & this, processor * proc ); 33 void ^?{}( preemption_scope & this ); 34 34 35 35 // Local Variables: // -
src/libcfa/concurrency/thread
r135b431 r6b224a52 27 27 // Anything that is resumed is a coroutine. 28 28 trait is_thread(dtype T) { 29 void ^?{}(T *mutex this);30 void main(T *this);31 thread_desc* get_thread(T *this);29 void ^?{}(T& mutex this); 30 void main(T& this); 31 thread_desc* get_thread(T& this); 32 32 }; 33 33 34 #define DECL_THREAD(X) thread_desc* get_thread(X * this) { return &this->__thrd; } void main(X*this)34 #define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this) 35 35 36 36 forall( dtype T | is_thread(T) ) 37 static inline coroutine_desc* get_coroutine(T *this) {37 static inline coroutine_desc* get_coroutine(T & this) { 38 38 return &get_thread(this)->cor; 39 39 } 40 40 41 41 forall( dtype T | is_thread(T) ) 42 static inline monitor_desc* get_monitor(T *this) {42 static inline monitor_desc* get_monitor(T & this) { 43 43 return &get_thread(this)->mon; 44 44 } … … 55 55 56 56 forall( dtype T | is_thread(T) ) 57 void __thrd_start( T *this );57 void __thrd_start( T & this ); 58 58 59 59 //----------------------------------------------------------------------------- 60 60 // Ctors and dtors 61 void ?{}(thread_desc *this);62 void ^?{}(thread_desc *this);61 void ?{}(thread_desc& this); 62 void ^?{}(thread_desc& this); 63 63 64 64 //----------------------------------------------------------------------------- … … 70 70 }; 71 71 72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T *); } )73 void ?{}( scoped(T) *this );72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) 73 void ?{}( scoped(T)& this ); 74 74 75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T *, P); } )76 void ?{}( scoped(T) *this, P params );75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) 76 void ?{}( scoped(T)& this, P params ); 77 77 78 78 forall( dtype T | sized(T) | is_thread(T) ) 79 void ^?{}( scoped(T) *this );79 void ^?{}( scoped(T)& this ); 80 80 81 81 void yield(); -
src/libcfa/concurrency/thread.c
r135b431 r6b224a52 32 32 // Thread ctors and dtors 33 33 34 void ?{}(thread_desc *this) {35 ( &this->cor){};36 this ->cor.name = "Anonymous Coroutine";37 this ->mon.owner =this;38 this ->mon.recursion = 1;39 this ->next = NULL;34 void ?{}(thread_desc& this) { 35 (this.cor){}; 36 this.cor.name = "Anonymous Coroutine"; 37 this.mon.owner = &this; 38 this.mon.recursion = 1; 39 this.next = NULL; 40 40 41 this ->current_monitors = &this->mon;42 this ->current_monitor_count = 1;41 this.current_monitors = &this.mon; 42 this.current_monitor_count = 1; 43 43 } 44 44 45 void ^?{}(thread_desc *this) {46 ^( &this->cor){};45 void ^?{}(thread_desc& this) { 46 ^(this.cor){}; 47 47 } 48 48 49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T *); } )50 void ?{}( scoped(T) *this ) {51 ( &this->handle){};52 __thrd_start( &this->handle);49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) 50 void ?{}( scoped(T)& this ) { 51 (this.handle){}; 52 __thrd_start(this.handle); 53 53 } 54 54 55 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T *, P); } )56 void ?{}( scoped(T) *this, P params ) {57 ( &this->handle){ params };58 __thrd_start( &this->handle);55 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) 56 void ?{}( scoped(T)& this, P params ) { 57 (this.handle){ params }; 58 __thrd_start(this.handle); 59 59 } 60 60 61 61 forall( dtype T | sized(T) | is_thread(T) ) 62 void ^?{}( scoped(T) *this ) {63 ^( &this->handle){};62 void ^?{}( scoped(T)& this ) { 63 ^(this.handle){}; 64 64 } 65 65 … … 67 67 // Starting and stopping threads 68 68 forall( dtype T | is_thread(T) ) 69 void __thrd_start( T *this ) {69 void __thrd_start( T& this ) { 70 70 coroutine_desc* thrd_c = get_coroutine(this); 71 71 thread_desc* thrd_h = get_thread (this); … … 77 77 create_stack(&thrd_c->stack, thrd_c->stack.size); 78 78 this_coroutine = thrd_c; 79 CtxStart( this, CtxInvokeThread);79 CtxStart(&this, CtxInvokeThread); 80 80 assert( thrd_c->last->stack.context ); 81 81 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
Note:
See TracChangeset
for help on using the changeset viewer.