Ignore:
File:
1 edited

Legend:

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

    r39fea2f r135b431  
    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         this.starter = NULL;
    105 }
    106 
    107 void ?{}( thread_desc & this, current_stack_info_t * info) {
    108         (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 };
    109108}
    110109
    111110//-----------------------------------------------------------------------------
    112111// Processor coroutine
    113 
    114 // Construct the processor context of the main processor
    115 void ?{}(processorCtx_t & this, processor * proc) {
    116         (this.__cor){ "Processor" };
    117         this.__cor.starter = &mainThread->cor;
    118         this.proc = proc;
    119         proc->runner = &this;
    120 }
    121 
    122 // Construct the processor context of non-main processors
    123 void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) {
    124         (this.__cor){ info };
    125         this.proc = proc;
    126         proc->runner = &this;
    127 }
    128 
    129 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) {
    130125        this{ mainCluster };
    131126}
    132127
    133 void ?{}(processor & this, cluster * cltr) {
    134         this.cltr = cltr;
    135         (this.terminated){ 0 };
    136         this.do_terminate = false;
    137         this.preemption_alarm = NULL;
    138         this.pending_preemption = false;
    139 
    140         start( &this );
    141 }
    142 
    143 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) {
    144         this.cltr = cltr;
    145         (this.terminated){ 0 };
    146         this.do_terminate = false;
    147         this.preemption_alarm = NULL;
    148         this.pending_preemption = false;
    149         this.kernel_thread = pthread_self();
    150 
    151         this.runner = &runner;
    152         LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);
    153         runner{ &this };
    154 }
    155 
    156 void ^?{}(processor & this) {
    157         if( ! this.do_terminate ) {
    158                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);
    159                 this.do_terminate = true;
    160                 P( &this.terminated );
    161                 pthread_join( this.kernel_thread, NULL );
    162         }
    163 }
    164 
    165 void ?{}(cluster & this) {
    166         ( this.ready_queue ){};
    167         ( this.ready_queue_lock ){};
    168 
    169         this.preemption = default_preemption();
    170 }
    171 
    172 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) {
    173168
    174169}
     
    178173//=============================================================================================
    179174//Main of the processor contexts
    180 void main(processorCtx_t & runner) {
    181         processor * this = runner.proc;
     175void main(processorCtx_t * runner) {
     176        processor * this = runner->proc;
    182177
    183178        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     
    224219// from the processor coroutine to the target thread
    225220void runThread(processor * this, thread_desc * dst) {
    226         coroutine_desc * proc_cor = get_coroutine(*this->runner);
     221        coroutine_desc * proc_cor = get_coroutine(this->runner);
    227222        coroutine_desc * thrd_cor = get_coroutine(dst);
    228223
     
    306301        // appropriate stack.
    307302        proc_cor_storage.__cor.state = Active;
    308         main( proc_cor_storage );
     303        main( &proc_cor_storage );
    309304        proc_cor_storage.__cor.state = Halted;
    310305
     
    448443        mainThread = (thread_desc *)&storage_mainThread;
    449444        current_stack_info_t info;
    450         (*mainThread){ &info };
     445        mainThread{ &info };
    451446
    452447        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     
    454449        // Initialize the main cluster
    455450        mainCluster = (cluster *)&storage_mainCluster;
    456         (*mainCluster){};
     451        mainCluster{};
    457452
    458453        LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
     
    461456        // (the coroutine that contains the processing control flow)
    462457        mainProcessor = (processor *)&storage_mainProcessor;
    463         (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
     458        mainProcessor{ mainCluster, (processorCtx_t *)&storage_mainProcessorCtx };
    464459
    465460        //initialize the global state variables
     
    478473        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    479474        // mainThread is on the ready queue when this call is made.
    480         resume( *mainProcessor->runner );
     475        resume( mainProcessor->runner );
    481476
    482477
     
    506501        // Destroy the main processor and its context in reverse order of construction
    507502        // These were manually constructed so we need manually destroy them
    508         ^(*mainProcessor->runner){};
     503        ^(mainProcessor->runner){};
    509504        ^(mainProcessor){};
    510505
     
    574569//-----------------------------------------------------------------------------
    575570// Locks
    576 void ?{}( spinlock & this ) {
    577         this.lock = 0;
    578 }
    579 void ^?{}( spinlock & this ) {
     571void ?{}( spinlock * this ) {
     572        this->lock = 0;
     573}
     574void ^?{}( spinlock * this ) {
    580575
    581576}
     
    611606}
    612607
    613 void  ?{}( semaphore & this, int count = 1 ) {
    614         (this.lock){};
    615         this.count = count;
    616         (this.waiting){};
    617 }
    618 void ^?{}(semaphore & this) {}
     608void  ?{}( semaphore * this, int count = 1 ) {
     609        (&this->lock){};
     610        this->count = count;
     611        (&this->waiting){};
     612}
     613void ^?{}(semaphore * this) {}
    619614
    620615void P(semaphore * this) {
     
    650645//-----------------------------------------------------------------------------
    651646// Queues
    652 void ?{}( __thread_queue_t & this ) {
    653         this.head = NULL;
    654         this.tail = &this.head;
     647void ?{}( __thread_queue_t * this ) {
     648        this->head = NULL;
     649        this->tail = &this->head;
    655650}
    656651
     
    690685}
    691686
    692 void ?{}( __condition_stack_t & this ) {
    693         this.top = NULL;
     687
     688
     689void ?{}( __condition_stack_t * this ) {
     690        this->top = NULL;
    694691}
    695692
Note: See TracChangeset for help on using the changeset viewer.