Ignore:
Timestamp:
Aug 25, 2017, 12:11:53 PM (7 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.