Ignore:
Timestamp:
Aug 25, 2017, 12:11:53 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa/concurrency
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    r135b431 r6b224a52  
    4040__cfa_time_t zero_time = { 0 };
    4141
    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 ) {
     42void ?{}( __cfa_time_t & this ) { this.val = 0; }
     43void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
     44
     45void ?{}( 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
     53void ?{}( __cfa_time_t & this, timespec * curr ) {
    5454        uint64_t secs  = curr->tv_sec;
    5555        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;
    6262}
    6363
     
    8686//=============================================================================================
    8787
    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 );
     88void ?{}( 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
     97void ?{}( 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
     106void ^?{}( alarm_node_t & this ) {
     107        if( this.set ) {
     108                unregister_self( &this );
    109109        }
    110110}
  • src/libcfa/concurrency/alarm.h

    r135b431 r6b224a52  
    3636
    3737// 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 );
     38void ?{}( __cfa_time_t & this );
     39void ?{}( __cfa_time_t & this, zero_t zero );
     40void ?{}( __cfa_time_t & this, timespec * curr );
     41void ?{}( itimerval & this, __cfa_time_t * alarm );
    4242
    43 __cfa_time_t ?=?( __cfa_time_t * this, zero_t rhs );
     43__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs );
    4444
    4545// logical ops
     
    105105typedef alarm_node_t ** __alarm_it_t;
    106106
    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 );
     107void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
     108void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
     109void ^?{}( alarm_node_t & this );
    110110
    111111struct alarm_list_t {
     
    114114};
    115115
    116 static inline void ?{}( alarm_list_t * this ) {
    117         this->head = 0;
    118         this->tail = &this->head;
     116static inline void ?{}( alarm_list_t & this ) {
     117        this.head = 0;
     118        this.tail = &this.head;
    119119}
    120120
  • src/libcfa/concurrency/coroutine

    r135b431 r6b224a52  
    2525// Anything that is resumed is a coroutine.
    2626trait 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);
    2929};
    3030
    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)
    3232
    3333//-----------------------------------------------------------------------------
    3434// 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);
     35void ?{}(coStack_t & this);
     36void ?{}(coroutine_desc & this);
     37void ?{}(coroutine_desc & this, const char * name);
     38void ^?{}(coStack_t & this);
     39void ^?{}(coroutine_desc & this);
    4040
    4141//-----------------------------------------------------------------------------
     
    4444
    4545forall(dtype T | is_coroutine(T))
    46 static inline void resume(T * cor);
     46static inline void resume(T & cor);
    4747
    4848forall(dtype T | is_coroutine(T))
    49 void prime(T * cor);
     49void prime(T & cor);
    5050
    5151//-----------------------------------------------------------------------------
     
    8686// Resume implementation inlined for performance
    8787forall(dtype T | is_coroutine(T))
    88 static inline void resume(T * cor) {
     88static inline void resume(T & cor) {
    8989        coroutine_desc * src = this_coroutine;          // optimization
    9090        coroutine_desc * dst = get_coroutine(cor);
     
    9292        if( unlikely(!dst->stack.base) ) {
    9393                create_stack(&dst->stack, dst->stack.size);
    94                 CtxStart(cor, CtxInvokeCoroutine);
     94                CtxStart(&cor, CtxInvokeCoroutine);
    9595        }
    9696
  • src/libcfa/concurrency/coroutine.c

    r135b431 r6b224a52  
    4040//-----------------------------------------------------------------------------
    4141// Coroutine ctors and dtors
    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;
     42void ?{}(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;
    5050}
    5151
    52 void ?{}(coStack_t* this, size_t size) {
     52void ?{}(coStack_t& this, size_t size) {
    5353        this{};
    54         this->size = size;
     54        this.size = size;
    5555
    56         create_stack(this, this->size);
     56        create_stack(&this, this.size);
    5757}
    5858
    59 void ?{}(coroutine_desc* this) {
     59void ?{}(coroutine_desc& this) {
    6060        this{ "Anonymous Coroutine" };
    6161}
    6262
    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;
     63void ?{}(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;
    6969}
    7070
    71 void ?{}(coroutine_desc* this, size_t size) {
     71void ?{}(coroutine_desc& this, size_t size) {
    7272        this{};
    73         (&this->stack){size};
     73        (this.stack){size};
    7474}
    7575
    76 void ^?{}(coStack_t* this) {
    77         if ( ! this->userStack ) {
     76void ^?{}(coStack_t& this) {
     77        if ( ! this.userStack ) {
    7878                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 ) );
    8181                        }
    8282                );
    83                 free( this->storage );
     83                free( this.storage );
    8484        }
    8585}
    8686
    87 void ^?{}(coroutine_desc* this) {}
     87void ^?{}(coroutine_desc& this) {}
    8888
    8989// Part of the Public API
    9090// Not inline since only ever called once per coroutine
    9191forall(dtype T | is_coroutine(T))
    92 void prime(T* cor) {
     92void prime(T& cor) {
    9393        coroutine_desc* this = get_coroutine(cor);
    9494        assert(this->state == Start);
  • src/libcfa/concurrency/invoke.h

    r135b431 r6b224a52  
    4949      #ifdef __CFORALL__
    5050      extern "Cforall" {
    51             void ?{}( struct __thread_queue_t * );
     51            void ?{}( struct __thread_queue_t & );
    5252            void append( struct __thread_queue_t *, struct thread_desc * );
    5353            struct thread_desc * pop_head( struct __thread_queue_t * );
    5454            struct thread_desc * remove( struct __thread_queue_t *, struct thread_desc ** );
    5555
    56             void ?{}( struct __condition_stack_t * );
     56            void ?{}( struct __condition_stack_t & );
    5757            void push( struct __condition_stack_t *, struct __condition_criterion_t * );
    5858            struct __condition_criterion_t * pop( struct __condition_stack_t * );
    5959
    60             void ?{}(spinlock * this);
    61             void ^?{}(spinlock * this);
     60            void ?{}(spinlock & this);
     61            void ^?{}(spinlock & this);
    6262      }
    6363      #endif
  • src/libcfa/concurrency/kernel

    r135b431 r6b224a52  
    3737};
    3838
    39 void  ?{}(semaphore * this, int count = 1);
    40 void ^?{}(semaphore * this);
     39void  ?{}(semaphore & this, int count = 1);
     40void ^?{}(semaphore & this);
    4141void P(semaphore * this);
    4242void V(semaphore * this);
     
    5151};
    5252
    53 void ?{}(cluster * this);
    54 void ^?{}(cluster * this);
     53void ?{}(cluster & this);
     54void ^?{}(cluster & this);
    5555
    5656//-----------------------------------------------------------------------------
     
    6868        unsigned short thrd_count;
    6969};
    70 static inline void ?{}(FinishAction * this) {
    71         this->action_code = No_Action;
    72         this->thrd = NULL;
    73         this->lock = NULL;
     70static inline void ?{}(FinishAction & this) {
     71        this.action_code = No_Action;
     72        this.thrd = NULL;
     73        this.lock = NULL;
    7474}
    75 static inline void ^?{}(FinishAction * this) {}
     75static inline void ^?{}(FinishAction & this) {}
    7676
    7777// Processor
     
    9999};
    100100
    101 void ?{}(processor * this);
    102 void ?{}(processor * this, cluster * cltr);
    103 void ^?{}(processor * this);
     101void ?{}(processor & this);
     102void ?{}(processor & this, cluster * cltr);
     103void ^?{}(processor & this);
    104104
    105105// Local Variables: //
  • src/libcfa/concurrency/kernel.c

    r135b431 r6b224a52  
    7373};
    7474
    75 void ?{}( current_stack_info_t * this ) {
    76         CtxGet( this->ctx );
    77         this->base = this->ctx.FP;
    78         this->storage = this->ctx.SP;
     75void ?{}( current_stack_info_t & this ) {
     76        CtxGet( this.ctx );
     77        this.base = this.ctx.FP;
     78        this.storage = this.ctx.SP;
    7979
    8080        rlimit r;
    8181        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
     89void ?{}( 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
     99void ?{}( 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
     106void ?{}( thread_desc & this, current_stack_info_t * info) {
     107        (this.cor){ info };
    108108}
    109109
    110110//-----------------------------------------------------------------------------
    111111// 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) {
     112void ?{}(processorCtx_t & this, processor * proc) {
     113        (this.__cor){ "Processor" };
     114        this.proc = proc;
     115        proc->runner = &this;
     116}
     117
     118void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) {
     119        (this.__cor){ info };
     120        this.proc = proc;
     121        proc->runner = &this;
     122}
     123
     124void ?{}(processor & this) {
    125125        this{ mainCluster };
    126126}
    127127
    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) {
     128void ?{}(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
     138void ?{}(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
     151void ^?{}(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
     160void ?{}(cluster & this) {
     161        ( this.ready_queue ){};
     162        ( this.ready_queue_lock ){};
     163
     164        this.preemption = default_preemption();
     165}
     166
     167void ^?{}(cluster & this) {
    168168
    169169}
     
    173173//=============================================================================================
    174174//Main of the processor contexts
    175 void main(processorCtx_t * runner) {
    176         processor * this = runner->proc;
     175void main(processorCtx_t & runner) {
     176        processor * this = runner.proc;
    177177
    178178        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     
    219219// from the processor coroutine to the target thread
    220220void runThread(processor * this, thread_desc * dst) {
    221         coroutine_desc * proc_cor = get_coroutine(this->runner);
     221        coroutine_desc * proc_cor = get_coroutine(*this->runner);
    222222        coroutine_desc * thrd_cor = get_coroutine(dst);
    223223
     
    301301        // appropriate stack.
    302302        proc_cor_storage.__cor.state = Active;
    303         main( &proc_cor_storage );
     303        main( proc_cor_storage );
    304304        proc_cor_storage.__cor.state = Halted;
    305305
     
    443443        mainThread = (thread_desc *)&storage_mainThread;
    444444        current_stack_info_t info;
    445         mainThread{ &info };
     445        (*mainThread){ &info };
    446446
    447447        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     
    449449        // Initialize the main cluster
    450450        mainCluster = (cluster *)&storage_mainCluster;
    451         mainCluster{};
     451        (*mainCluster){};
    452452
    453453        LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
     
    456456        // (the coroutine that contains the processing control flow)
    457457        mainProcessor = (processor *)&storage_mainProcessor;
    458         mainProcessor{ mainCluster, (processorCtx_t *)&storage_mainProcessorCtx };
     458        (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
    459459
    460460        //initialize the global state variables
     
    473473        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    474474        // mainThread is on the ready queue when this call is made.
    475         resume( mainProcessor->runner );
     475        resume( *mainProcessor->runner );
    476476
    477477
     
    501501        // Destroy the main processor and its context in reverse order of construction
    502502        // These were manually constructed so we need manually destroy them
    503         ^(mainProcessor->runner){};
     503        ^(*mainProcessor->runner){};
    504504        ^(mainProcessor){};
    505505
     
    569569//-----------------------------------------------------------------------------
    570570// Locks
    571 void ?{}( spinlock * this ) {
    572         this->lock = 0;
    573 }
    574 void ^?{}( spinlock * this ) {
     571void ?{}( spinlock & this ) {
     572        this.lock = 0;
     573}
     574void ^?{}( spinlock & this ) {
    575575
    576576}
     
    606606}
    607607
    608 void  ?{}( semaphore * this, int count = 1 ) {
    609         (&this->lock){};
    610         this->count = count;
    611         (&this->waiting){};
    612 }
    613 void ^?{}(semaphore * this) {}
     608void  ?{}( semaphore & this, int count = 1 ) {
     609        (this.lock){};
     610        this.count = count;
     611        (this.waiting){};
     612}
     613void ^?{}(semaphore & this) {}
    614614
    615615void P(semaphore * this) {
     
    645645//-----------------------------------------------------------------------------
    646646// Queues
    647 void ?{}( __thread_queue_t * this ) {
    648         this->head = NULL;
    649         this->tail = &this->head;
     647void ?{}( __thread_queue_t & this ) {
     648        this.head = NULL;
     649        this.tail = &this.head;
    650650}
    651651
     
    685685}
    686686
    687 
    688 
    689 void ?{}( __condition_stack_t * this ) {
    690         this->top = NULL;
     687void ?{}( __condition_stack_t & this ) {
     688        this.top = NULL;
    691689}
    692690
  • src/libcfa/concurrency/monitor

    r135b431 r6b224a52  
    2222#include "stdlib"
    2323
    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;
     24static 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;
    3333}
    3434
     
    4545}
    4646
    47 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() );
    48 void ^?{}( monitor_guard_t * this );
     47void ?{}( monitor_guard_t & this, monitor_desc ** m, int count );
     48void ^?{}( monitor_guard_t & this );
    4949
    5050//-----------------------------------------------------------------------------
     
    7171};
    7272
    73 void ?{}( __condition_blocked_queue_t * );
     73void ?{}( __condition_blocked_queue_t & );
    7474void append( __condition_blocked_queue_t *, __condition_node_t * );
    7575__condition_node_t * pop_head( __condition_blocked_queue_t * );
     
    8181};
    8282
    83 static inline void ?{}( condition * this ) {
    84         this->monitors = NULL;
    85         this->monitor_count = 0;
     83static inline void ?{}( condition & this ) {
     84        this.monitors = NULL;
     85        this.monitor_count = 0;
    8686}
    8787
    88 static inline void ^?{}( condition * this ) {
    89         free( this->monitors );
     88static inline void ^?{}( condition & this ) {
     89        free( this.monitors );
    9090}
    9191
  • src/libcfa/concurrency/monitor.c

    r135b431 r6b224a52  
    194194// Ctor for monitor guard
    195195// Sorts monitors before entering
    196 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() ) {
     196void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() ) {
    197197        // Store current array
    198         this->m = m;
    199         this->count = count;
     198        this.m = m;
     199        this.count = count;
    200200
    201201        // Sort monitors based on address -> TODO use a sort specialized for small numbers
    202         qsort(this->m, count);
     202        qsort(this.m, count);
    203203
    204204        // 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;
    208208
    209209        // Update thread context (needed for conditions)
     
    213213
    214214        // Enter the monitors in order
    215         enter( this->m, this->count, func );
    216 }
     215        enter( this.m, this.count, func );
     216}
     217
    217218
    218219// Dtor for monitor guard
    219 void ^?{}( monitor_guard_t * this ) {
     220void ^?{}( monitor_guard_t & this ) {
    220221        // Leave the monitors in order
    221         leave( this->m, this->count );
     222        leave( this.m, this.count );
    222223
    223224        // 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;
    227228}
    228229
    229230//-----------------------------------------------------------------------------
    230231// 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;
     232void ?{}(__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
     239void ?{}(__condition_criterion_t & this ) {
     240        this.ready  = false;
     241        this.target = NULL;
     242        this.owner  = NULL;
     243        this.next   = NULL;
     244}
     245
     246void ?{}(__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;
    251251}
    252252
     
    523523static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    524524        for(int i = 0; i < count; i++) {
    525                 (&criteria[i]){ monitors[i], waiter };
     525                (criteria[i]){ monitors[i], waiter };
    526526        }
    527527
     
    531531static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    532532        for(int i = 0; i < count; i++) {
    533                 (&criteria[i]){ monitors[i], waiter };
     533                (criteria[i]){ monitors[i], waiter };
    534534                push( &criteria[i].target->signal_stack, &criteria[i] );
    535535        }
     
    627627        return end + 1;
    628628}
     629
    629630
    630631static inline bool match( __acceptable_t * acc, thread_desc * thrd ) {
     
    660661        return NULL;
    661662}
    662 
    663 void ?{}( __condition_blocked_queue_t * this ) {
    664         this->head = NULL;
    665         this->tail = &this->head;
     663void ?{}( __condition_blocked_queue_t & this ) {
     664        this.head = NULL;
     665        this.tail = &this.head;
    666666}
    667667
  • src/libcfa/concurrency/preemption.c

    r135b431 r6b224a52  
    7171static pthread_t alarm_thread;                        // pthread handle to alarm thread
    7272
    73 void ?{}(event_kernel_t * this) {
    74         (&this->alarms){};
    75         (&this->lock){};
     73void ?{}(event_kernel_t & this) {
     74        (this.alarms){};
     75        (this.lock){};
    7676}
    7777
     
    240240        // Initialize the event kernel
    241241        event_kernel = (event_kernel_t *)&storage_event_kernel;
    242         event_kernel{};
     242        (*event_kernel){};
    243243
    244244        // Setup proper signal handlers
     
    276276// Raii ctor/dtor for the preemption_scope
    277277// 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 ) {
     278void ?{}( 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
     286void ^?{}( preemption_scope & this ) {
    287287        disable_interrupts();
    288288
    289         update_preemption( this->proc, zero_time );
     289        update_preemption( this.proc, zero_time );
    290290}
    291291
  • src/libcfa/concurrency/preemption.h

    r135b431 r6b224a52  
    3030};
    3131
    32 void ?{}( preemption_scope * this, processor * proc );
    33 void ^?{}( preemption_scope * this );
     32void ?{}( preemption_scope & this, processor * proc );
     33void ^?{}( preemption_scope & this );
    3434
    3535// Local Variables: //
  • src/libcfa/concurrency/thread

    r135b431 r6b224a52  
    2727// Anything that is resumed is a coroutine.
    2828trait 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);
    3232};
    3333
    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)
    3535
    3636forall( dtype T | is_thread(T) )
    37 static inline coroutine_desc* get_coroutine(T* this) {
     37static inline coroutine_desc* get_coroutine(T & this) {
    3838        return &get_thread(this)->cor;
    3939}
    4040
    4141forall( dtype T | is_thread(T) )
    42 static inline monitor_desc* get_monitor(T * this) {
     42static inline monitor_desc* get_monitor(T & this) {
    4343        return &get_thread(this)->mon;
    4444}
     
    5555
    5656forall( dtype T | is_thread(T) )
    57 void __thrd_start( T* this );
     57void __thrd_start( T & this );
    5858
    5959//-----------------------------------------------------------------------------
    6060// Ctors and dtors
    61 void ?{}(thread_desc* this);
    62 void ^?{}(thread_desc* this);
     61void ?{}(thread_desc& this);
     62void ^?{}(thread_desc& this);
    6363
    6464//-----------------------------------------------------------------------------
     
    7070};
    7171
    72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
    73 void ?{}( scoped(T)* this );
     72forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     73void ?{}( scoped(T)& this );
    7474
    75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
    76 void ?{}( scoped(T)* this, P params );
     75forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     76void ?{}( scoped(T)& this, P params );
    7777
    7878forall( dtype T | sized(T) | is_thread(T) )
    79 void ^?{}( scoped(T)* this );
     79void ^?{}( scoped(T)& this );
    8080
    8181void yield();
  • src/libcfa/concurrency/thread.c

    r135b431 r6b224a52  
    3232// Thread ctors and dtors
    3333
    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;
     34void ?{}(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;
    4040
    41         this->current_monitors      = &this->mon;
    42         this->current_monitor_count = 1;
     41        this.current_monitors      = &this.mon;
     42        this.current_monitor_count = 1;
    4343}
    4444
    45 void ^?{}(thread_desc* this) {
    46         ^(&this->cor){};
     45void ^?{}(thread_desc& this) {
     46        ^(this.cor){};
    4747}
    4848
    49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
    50 void ?{}( scoped(T)* this ) {
    51         (&this->handle){};
    52         __thrd_start(&this->handle);
     49forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     50void ?{}( scoped(T)& this ) {
     51        (this.handle){};
     52        __thrd_start(this.handle);
    5353}
    5454
    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);
     55forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     56void ?{}( scoped(T)& this, P params ) {
     57        (this.handle){ params };
     58        __thrd_start(this.handle);
    5959}
    6060
    6161forall( dtype T | sized(T) | is_thread(T) )
    62 void ^?{}( scoped(T)* this ) {
    63         ^(&this->handle){};
     62void ^?{}( scoped(T)& this ) {
     63        ^(this.handle){};
    6464}
    6565
     
    6767// Starting and stopping threads
    6868forall( dtype T | is_thread(T) )
    69 void __thrd_start( T* this ) {
     69void __thrd_start( T& this ) {
    7070        coroutine_desc* thrd_c = get_coroutine(this);
    7171        thread_desc*  thrd_h = get_thread   (this);
     
    7777        create_stack(&thrd_c->stack, thrd_c->stack.size);
    7878        this_coroutine = thrd_c;
    79         CtxStart(this, CtxInvokeThread);
     79        CtxStart(&this, CtxInvokeThread);
    8080        assert( thrd_c->last->stack.context );
    8181        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
Note: See TracChangeset for help on using the changeset viewer.