Ignore:
Timestamp:
Jan 30, 2018, 3:52:42 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, stuck-waitfor-destruct, with_gc
Children:
f792cb8
Parents:
5b51f5e
Message:

Kernel now properly uses with statments

File:
1 edited

Legend:

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

    r5b51f5e r65deb18  
    8585}
    8686
    87 void ?{}( coStack_t & this, current_stack_info_t * info) {
    88         this.size = info->size;
    89         this.storage = info->storage;
    90         this.limit = info->limit;
    91         this.base = info->base;
    92         this.context = info->context;
    93         this.top = info->top;
    94         this.userStack = true;
    95 }
    96 
    97 void ?{}( coroutine_desc & this, current_stack_info_t * info) {
    98         (this.stack){ info };
    99         this.name = "Main Thread";
    100         this.errno_ = 0;
    101         this.state = Start;
    102         this.starter = NULL;
    103 }
    104 
    105 void ?{}( thread_desc & this, current_stack_info_t * info) {
    106         (this.self_cor){ info };
     87void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
     88        size      = info->size;
     89        storage  = info->storage;
     90        limit    = info->limit;
     91        base      = info->base;
     92        context  = info->context;
     93        top      = info->top;
     94        userStack = true;
     95}
     96
     97void ?{}( coroutine_desc & this, current_stack_info_t * info) with( this ) {
     98        stack{ info };
     99        name = "Main Thread";
     100        errno_ = 0;
     101        state = Start;
     102        starter = NULL;
     103}
     104
     105void ?{}( thread_desc & this, current_stack_info_t * info) with( this ) {
     106        self_cor{ info };
    107107}
    108108
     
    131131void ?{}(processor & this, cluster * cltr) {
    132132        this.cltr = cltr;
    133         (this.terminated){ 0 };
     133        this.terminated{ 0 };
    134134        this.do_terminate = false;
    135135        this.preemption_alarm = NULL;
     
    141141void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) {
    142142        this.cltr = cltr;
    143         (this.terminated){ 0 };
     143        this.terminated{ 0 };
    144144        this.do_terminate = false;
    145145        this.preemption_alarm = NULL;
     
    152152}
    153153
    154 void ^?{}(processor & this) {
    155         if( ! this.do_terminate ) {
     154void ^?{}(processor & this) with( this ){
     155        if( ! do_terminate ) {
    156156                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    157                 this.do_terminate = true;
    158                 P( this.terminated );
    159                 pthread_join( this.kernel_thread, NULL );
    160         }
    161 }
    162 
    163 void ?{}(cluster & this) {
    164         (this.ready_queue){};
    165         ( this.ready_queue_lock ){};
    166 
    167         this.preemption = default_preemption();
     157                do_terminate = true;
     158                P( terminated );
     159                pthread_join( kernel_thread, NULL );
     160        }
     161}
     162
     163void ?{}(cluster & this) with( this ) {
     164        ready_queue{};
     165        ready_queue_lock{};
     166
     167        preemption = default_preemption();
    168168}
    169169
     
    238238// Once a thread has finished running, some of
    239239// its final actions must be executed from the kernel
    240 void finishRunning(processor * this) {
    241         if( this->finish.action_code == Release ) {
    242                 unlock( *this->finish.lock );
    243         }
    244         else if( this->finish.action_code == Schedule ) {
    245                 ScheduleThread( this->finish.thrd );
    246         }
    247         else if( this->finish.action_code == Release_Schedule ) {
    248                 unlock( *this->finish.lock );
    249                 ScheduleThread( this->finish.thrd );
    250         }
    251         else if( this->finish.action_code == Release_Multi ) {
    252                 for(int i = 0; i < this->finish.lock_count; i++) {
    253                         unlock( *this->finish.locks[i] );
     240void finishRunning(processor * this) with( this->finish ) {
     241        if( action_code == Release ) {
     242                unlock( *lock );
     243        }
     244        else if( action_code == Schedule ) {
     245                ScheduleThread( thrd );
     246        }
     247        else if( action_code == Release_Schedule ) {
     248                unlock( *lock );
     249                ScheduleThread( thrd );
     250        }
     251        else if( action_code == Release_Multi ) {
     252                for(int i = 0; i < lock_count; i++) {
     253                        unlock( *locks[i] );
    254254                }
    255255        }
    256         else if( this->finish.action_code == Release_Multi_Schedule ) {
    257                 for(int i = 0; i < this->finish.lock_count; i++) {
    258                         unlock( *this->finish.locks[i] );
     256        else if( action_code == Release_Multi_Schedule ) {
     257                for(int i = 0; i < lock_count; i++) {
     258                        unlock( *locks[i] );
    259259                }
    260                 for(int i = 0; i < this->finish.thrd_count; i++) {
    261                         ScheduleThread( this->finish.thrds[i] );
     260                for(int i = 0; i < thrd_count; i++) {
     261                        ScheduleThread( thrds[i] );
    262262                }
    263263        }
    264264        else {
    265                 assert(this->finish.action_code == No_Action);
     265                assert(action_code == No_Action);
    266266        }
    267267}
     
    332332        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    333333
    334         lock(   this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 );
    335         append( this_processor->cltr->ready_queue, thrd );
    336         unlock( this_processor->cltr->ready_queue_lock );
    337 
    338         verify( disable_preempt_count > 0 );
    339 }
    340 
    341 thread_desc * nextThread(cluster * this) {
    342         verify( disable_preempt_count > 0 );
    343         lock( this->ready_queue_lock __cfaabi_dbg_ctx2 );
    344         thread_desc * head = pop_head( this->ready_queue );
    345         unlock( this->ready_queue_lock );
     334        with( *this_processor->cltr ) {
     335                lock  ( ready_queue_lock __cfaabi_dbg_ctx2 );
     336                append( ready_queue, thrd );
     337                unlock( ready_queue_lock );
     338        }
     339
     340        verify( disable_preempt_count > 0 );
     341}
     342
     343thread_desc * nextThread(cluster * this) with( *this ) {
     344        verify( disable_preempt_count > 0 );
     345        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
     346        thread_desc * head = pop_head( ready_queue );
     347        unlock( ready_queue_lock );
    346348        verify( disable_preempt_count > 0 );
    347349        return head;
     
    359361        disable_interrupts();
    360362        this_processor->finish.action_code = Release;
    361         this_processor->finish.lock = lock;
     363        this_processor->finish.lock        = lock;
    362364
    363365        verify( disable_preempt_count > 0 );
     
    369371
    370372void BlockInternal( thread_desc * thrd ) {
    371         assert(thrd);
    372373        disable_interrupts();
    373         assert( thrd->self_cor.state != Halted );
    374374        this_processor->finish.action_code = Schedule;
    375         this_processor->finish.thrd = thrd;
     375        this_processor->finish.thrd        = thrd;
    376376
    377377        verify( disable_preempt_count > 0 );
     
    386386        disable_interrupts();
    387387        this_processor->finish.action_code = Release_Schedule;
    388         this_processor->finish.lock = lock;
    389         this_processor->finish.thrd = thrd;
     388        this_processor->finish.lock        = lock;
     389        this_processor->finish.thrd        = thrd;
    390390
    391391        verify( disable_preempt_count > 0 );
     
    399399        disable_interrupts();
    400400        this_processor->finish.action_code = Release_Multi;
    401         this_processor->finish.locks = locks;
    402         this_processor->finish.lock_count = count;
     401        this_processor->finish.locks       = locks;
     402        this_processor->finish.lock_count  = count;
    403403
    404404        verify( disable_preempt_count > 0 );
     
    412412        disable_interrupts();
    413413        this_processor->finish.action_code = Release_Multi_Schedule;
    414         this_processor->finish.locks = locks;
    415         this_processor->finish.lock_count = lock_count;
    416         this_processor->finish.thrds = thrds;
    417         this_processor->finish.thrd_count = thrd_count;
     414        this_processor->finish.locks       = locks;
     415        this_processor->finish.lock_count  = lock_count;
     416        this_processor->finish.thrds       = thrds;
     417        this_processor->finish.thrd_count  = thrd_count;
    418418
    419419        verify( disable_preempt_count > 0 );
     
    427427        verify( disable_preempt_count > 0 );
    428428        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    429         this_processor->finish.lock = lock;
    430         this_processor->finish.thrd = thrd;
     429        this_processor->finish.lock        = lock;
     430        this_processor->finish.thrd        = thrd;
    431431
    432432        suspend();
     
    579579void ^?{}(semaphore & this) {}
    580580
    581 void P(semaphore & this) {
    582         lock( this.lock __cfaabi_dbg_ctx2 );
    583         this.count -= 1;
    584         if ( this.count < 0 ) {
     581void P(semaphore & this) with( this ){
     582        lock( lock __cfaabi_dbg_ctx2 );
     583        count -= 1;
     584        if ( count < 0 ) {
    585585                // queue current task
    586                 append( this.waiting, (thread_desc *)this_thread );
     586                append( waiting, (thread_desc *)this_thread );
    587587
    588588                // atomically release spin lock and block
    589                 BlockInternal( &this.lock );
     589                BlockInternal( &lock );
    590590        }
    591591        else {
    592             unlock( this.lock );
    593         }
    594 }
    595 
    596 void V(semaphore & this) {
     592            unlock( lock );
     593        }
     594}
     595
     596void V(semaphore & this) with( this ) {
    597597        thread_desc * thrd = NULL;
    598         lock( this.lock __cfaabi_dbg_ctx2 );
    599         this.count += 1;
    600         if ( this.count <= 0 ) {
     598        lock( lock __cfaabi_dbg_ctx2 );
     599        count += 1;
     600        if ( count <= 0 ) {
    601601                // remove task at head of waiting list
    602                 thrd = pop_head( this.waiting );
    603         }
    604 
    605         unlock( this.lock );
     602                thrd = pop_head( waiting );
     603        }
     604
     605        unlock( lock );
    606606
    607607        // make new owner
Note: See TracChangeset for help on using the changeset viewer.