Ignore:
Timestamp:
Jan 31, 2018, 5:50:34 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
295e5071
Parents:
bc6f918 (diff), 281806b (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:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rbc6f918 re2e7330  
    8787}
    8888
    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.self_cor){ info };
     89void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
     90        size      = info->size;
     91        storage  = info->storage;
     92        limit    = info->limit;
     93        base      = info->base;
     94        context  = info->context;
     95        top      = info->top;
     96        userStack = true;
     97}
     98
     99void ?{}( coroutine_desc & this, current_stack_info_t * info) with( this ) {
     100        stack{ info };
     101        name = "Main Thread";
     102        errno_ = 0;
     103        state = Start;
     104        starter = NULL;
     105}
     106
     107void ?{}( thread_desc & this, current_stack_info_t * info) with( this ) {
     108        self_cor{ info };
    109109}
    110110
     
    133133void ?{}(processor & this, cluster * cltr) {
    134134        this.cltr = cltr;
    135         (this.terminated){ 0 };
     135        this.terminated{ 0 };
    136136        this.do_terminate = false;
    137137        this.preemption_alarm = NULL;
     
    143143void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) {
    144144        this.cltr = cltr;
    145         (this.terminated){ 0 };
     145        this.terminated{ 0 };
    146146        this.do_terminate = false;
    147147        this.preemption_alarm = NULL;
     
    154154}
    155155
    156 void ^?{}(processor & this) {
    157         if( ! this.do_terminate ) {
     156void ^?{}(processor & this) with( this ){
     157        if( ! do_terminate ) {
    158158                __cfaabi_dbg_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();
     159                do_terminate = true;
     160                P( terminated );
     161                pthread_join( kernel_thread, NULL );
     162        }
     163}
     164
     165void ?{}(cluster & this) with( this ) {
     166        ready_queue{};
     167        ready_queue_lock{};
     168
     169        preemption = default_preemption();
    170170}
    171171
     
    240240// Once a thread has finished running, some of
    241241// its final actions must be executed from the kernel
    242 void finishRunning(processor * this) {
    243         if( this->finish.action_code == Release ) {
    244                 unlock( *this->finish.lock );
    245         }
    246         else if( this->finish.action_code == Schedule ) {
    247                 ScheduleThread( this->finish.thrd );
    248         }
    249         else if( this->finish.action_code == Release_Schedule ) {
    250                 unlock( *this->finish.lock );
    251                 ScheduleThread( this->finish.thrd );
    252         }
    253         else if( this->finish.action_code == Release_Multi ) {
    254                 for(int i = 0; i < this->finish.lock_count; i++) {
    255                         unlock( *this->finish.locks[i] );
     242void finishRunning(processor * this) with( this->finish ) {
     243        if( action_code == Release ) {
     244                verify( disable_preempt_count > 1 );
     245                unlock( *lock );
     246        }
     247        else if( action_code == Schedule ) {
     248                ScheduleThread( thrd );
     249        }
     250        else if( action_code == Release_Schedule ) {
     251                verify( disable_preempt_count > 1 );
     252                unlock( *lock );
     253                ScheduleThread( thrd );
     254        }
     255        else if( action_code == Release_Multi ) {
     256                verify( disable_preempt_count > lock_count );
     257                for(int i = 0; i < lock_count; i++) {
     258                        unlock( *locks[i] );
    256259                }
    257260        }
    258         else if( this->finish.action_code == Release_Multi_Schedule ) {
    259                 for(int i = 0; i < this->finish.lock_count; i++) {
    260                         unlock( *this->finish.locks[i] );
     261        else if( action_code == Release_Multi_Schedule ) {
     262                for(int i = 0; i < lock_count; i++) {
     263                        unlock( *locks[i] );
    261264                }
    262                 for(int i = 0; i < this->finish.thrd_count; i++) {
    263                         ScheduleThread( this->finish.thrds[i] );
     265                for(int i = 0; i < thrd_count; i++) {
     266                        ScheduleThread( thrds[i] );
    264267                }
    265268        }
    266269        else {
    267                 assert(this->finish.action_code == No_Action);
     270                assert(action_code == No_Action);
    268271        }
    269272}
     
    334337        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    335338
    336         lock(   this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 );
    337         append( this_processor->cltr->ready_queue, thrd );
    338         unlock( this_processor->cltr->ready_queue_lock );
    339 
    340         verify( disable_preempt_count > 0 );
    341 }
    342 
    343 thread_desc * nextThread(cluster * this) {
    344         verify( disable_preempt_count > 0 );
    345         lock( this->ready_queue_lock __cfaabi_dbg_ctx2 );
    346         thread_desc * head = pop_head( this->ready_queue );
    347         unlock( this->ready_queue_lock );
     339        with( *this_processor->cltr ) {
     340                lock  ( ready_queue_lock __cfaabi_dbg_ctx2 );
     341                append( ready_queue, thrd );
     342                unlock( ready_queue_lock );
     343        }
     344
     345        verify( disable_preempt_count > 0 );
     346}
     347
     348thread_desc * nextThread(cluster * this) with( *this ) {
     349        verify( disable_preempt_count > 0 );
     350        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
     351        thread_desc * head = pop_head( ready_queue );
     352        unlock( ready_queue_lock );
    348353        verify( disable_preempt_count > 0 );
    349354        return head;
     
    361366        disable_interrupts();
    362367        this_processor->finish.action_code = Release;
    363         this_processor->finish.lock = lock;
    364 
    365         verify( disable_preempt_count > 0 );
     368        this_processor->finish.lock        = lock;
     369
     370        verify( disable_preempt_count > 1 );
    366371        suspend();
    367372        verify( disable_preempt_count > 0 );
     
    371376
    372377void BlockInternal( thread_desc * thrd ) {
    373         assert(thrd);
    374378        disable_interrupts();
    375         assert( thrd->self_cor.state != Halted );
    376379        this_processor->finish.action_code = Schedule;
    377         this_processor->finish.thrd = thrd;
     380        this_processor->finish.thrd        = thrd;
    378381
    379382        verify( disable_preempt_count > 0 );
     
    388391        disable_interrupts();
    389392        this_processor->finish.action_code = Release_Schedule;
    390         this_processor->finish.lock = lock;
    391         this_processor->finish.thrd = thrd;
    392 
    393         verify( disable_preempt_count > 0 );
     393        this_processor->finish.lock        = lock;
     394        this_processor->finish.thrd        = thrd;
     395
     396        verify( disable_preempt_count > 1 );
    394397        suspend();
    395398        verify( disable_preempt_count > 0 );
     
    401404        disable_interrupts();
    402405        this_processor->finish.action_code = Release_Multi;
    403         this_processor->finish.locks = locks;
    404         this_processor->finish.lock_count = count;
     406        this_processor->finish.locks       = locks;
     407        this_processor->finish.lock_count  = count;
    405408
    406409        verify( disable_preempt_count > 0 );
     
    414417        disable_interrupts();
    415418        this_processor->finish.action_code = Release_Multi_Schedule;
    416         this_processor->finish.locks = locks;
    417         this_processor->finish.lock_count = lock_count;
    418         this_processor->finish.thrds = thrds;
    419         this_processor->finish.thrd_count = thrd_count;
     419        this_processor->finish.locks       = locks;
     420        this_processor->finish.lock_count  = lock_count;
     421        this_processor->finish.thrds       = thrds;
     422        this_processor->finish.thrd_count  = thrd_count;
    420423
    421424        verify( disable_preempt_count > 0 );
     
    429432        verify( disable_preempt_count > 0 );
    430433        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    431         this_processor->finish.lock = lock;
    432         this_processor->finish.thrd = thrd;
     434        this_processor->finish.lock        = lock;
     435        this_processor->finish.thrd        = thrd;
    433436
    434437        suspend();
     
    516519}
    517520
     521//=============================================================================================
     522// Unexpected Terminating logic
     523//=============================================================================================
     524
     525
    518526static __spinlock_t kernel_abort_lock;
    519527static __spinlock_t kernel_debug_lock;
     
    581589void ^?{}(semaphore & this) {}
    582590
    583 void P(semaphore & this) {
    584         lock( this.lock __cfaabi_dbg_ctx2 );
    585         this.count -= 1;
    586         if ( this.count < 0 ) {
     591void P(semaphore & this) with( this ){
     592        lock( lock __cfaabi_dbg_ctx2 );
     593        count -= 1;
     594        if ( count < 0 ) {
    587595                // queue current task
    588                 append( this.waiting, (thread_desc *)this_thread );
     596                append( waiting, (thread_desc *)this_thread );
    589597
    590598                // atomically release spin lock and block
    591                 BlockInternal( &this.lock );
     599                BlockInternal( &lock );
    592600        }
    593601        else {
    594             unlock( this.lock );
    595         }
    596 }
    597 
    598 void V(semaphore & this) {
     602            unlock( lock );
     603        }
     604}
     605
     606void V(semaphore & this) with( this ) {
    599607        thread_desc * thrd = NULL;
    600         lock( this.lock __cfaabi_dbg_ctx2 );
    601         this.count += 1;
    602         if ( this.count <= 0 ) {
     608        lock( lock __cfaabi_dbg_ctx2 );
     609        count += 1;
     610        if ( count <= 0 ) {
    603611                // remove task at head of waiting list
    604                 thrd = pop_head( this.waiting );
    605         }
    606 
    607         unlock( this.lock );
     612                thrd = pop_head( waiting );
     613        }
     614
     615        unlock( lock );
    608616
    609617        // make new owner
     
    611619}
    612620
     621//-----------------------------------------------------------------------------
     622// Debug
     623__cfaabi_dbg_debug_do(
     624        struct {
     625                thread_desc * tail;
     626        } __cfaabi_dbg_thread_list = { NULL };
     627
     628        void __cfaabi_dbg_thread_register( thread_desc * thrd ) {
     629                if( !__cfaabi_dbg_thread_list.tail ) {
     630                        __cfaabi_dbg_thread_list.tail = thrd;
     631                        return;
     632                }
     633                __cfaabi_dbg_thread_list.tail->dbg_next = thrd;
     634                thrd->dbg_prev = __cfaabi_dbg_thread_list.tail;
     635                __cfaabi_dbg_thread_list.tail = thrd;
     636        }
     637
     638        void __cfaabi_dbg_thread_unregister( thread_desc * thrd ) {
     639                thread_desc * prev = thrd->dbg_prev;
     640                thread_desc * next = thrd->dbg_next;
     641
     642                if( next ) { next->dbg_prev = prev; }
     643                else       {
     644                        assert( __cfaabi_dbg_thread_list.tail == thrd );
     645                        __cfaabi_dbg_thread_list.tail = prev;
     646                }
     647
     648                if( prev ) { prev->dbg_next = next; }
     649
     650                thrd->dbg_prev = NULL;
     651                thrd->dbg_next = NULL;
     652        }
     653)
    613654// Local Variables: //
    614655// mode: c //
Note: See TracChangeset for help on using the changeset viewer.