Ignore:
Timestamp:
Feb 1, 2018, 5:37:37 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
85521c7
Parents:
e76bd39
Message:

Faster (but maybe unsafe) interupt management

File:
1 edited

Legend:

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

    re76bd39 rd0a045c  
    5959
    6060volatile thread_local bool preemption_in_progress = 0;
     61volatile thread_local bool preemption_enabled = false;
    6162volatile thread_local unsigned short disable_preempt_count = 1;
    6263
     
    196197                        if(readyThread)
    197198                        {
    198                                 verify( disable_preempt_count > 0 );
     199                                verify( !preemption_enabled );
    199200
    200201                                runThread(this, readyThread);
    201202
    202                                 verify( disable_preempt_count > 0 );
     203                                verify( !preemption_enabled );
    203204
    204205                                //Some actions need to be taken from the kernel
     
    242243void finishRunning(processor * this) with( this->finish ) {
    243244        if( action_code == Release ) {
    244                 verify( disable_preempt_count > 1 );
     245                verify( !preemption_enabled );
    245246                unlock( *lock );
    246247        }
     
    249250        }
    250251        else if( action_code == Release_Schedule ) {
    251                 verify( disable_preempt_count > 1 );
     252                verify( !preemption_enabled );
    252253                unlock( *lock );
    253254                ScheduleThread( thrd );
    254255        }
    255256        else if( action_code == Release_Multi ) {
    256                 verify( disable_preempt_count > lock_count );
     257                verify( !preemption_enabled );
    257258                for(int i = 0; i < lock_count; i++) {
    258259                        unlock( *locks[i] );
     
    286287        this_coroutine = NULL;
    287288        this_thread = NULL;
     289        preemption_enabled = false;
    288290        disable_preempt_count = 1;
    289291        // SKULLDUGGERY: We want to create a context for the processor coroutine
     
    333335        verify( thrd->self_cor.state != Halted );
    334336
    335         verify( disable_preempt_count > 0 );
     337        verify( !preemption_enabled );
    336338
    337339        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    343345        }
    344346
    345         verify( disable_preempt_count > 0 );
     347        verify( !preemption_enabled );
    346348}
    347349
    348350thread_desc * nextThread(cluster * this) with( *this ) {
    349         verify( disable_preempt_count > 0 );
     351        verify( !preemption_enabled );
    350352        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    351353        thread_desc * head = pop_head( ready_queue );
    352354        unlock( ready_queue_lock );
    353         verify( disable_preempt_count > 0 );
     355        verify( !preemption_enabled );
    354356        return head;
    355357}
     
    357359void BlockInternal() {
    358360        disable_interrupts();
    359         verify( disable_preempt_count > 0 );
    360         suspend();
    361         verify( disable_preempt_count > 0 );
     361        verify( !preemption_enabled );
     362        suspend();
     363        verify( !preemption_enabled );
    362364        enable_interrupts( __cfaabi_dbg_ctx );
    363365}
     
    368370        this_processor->finish.lock        = lock;
    369371
    370         verify( disable_preempt_count > 1 );
    371         suspend();
    372         verify( disable_preempt_count > 0 );
     372        verify( !preemption_enabled );
     373        suspend();
     374        verify( !preemption_enabled );
    373375
    374376        enable_interrupts( __cfaabi_dbg_ctx );
     
    380382        this_processor->finish.thrd        = thrd;
    381383
    382         verify( disable_preempt_count > 0 );
    383         suspend();
    384         verify( disable_preempt_count > 0 );
     384        verify( !preemption_enabled );
     385        suspend();
     386        verify( !preemption_enabled );
    385387
    386388        enable_interrupts( __cfaabi_dbg_ctx );
     
    394396        this_processor->finish.thrd        = thrd;
    395397
    396         verify( disable_preempt_count > 1 );
    397         suspend();
    398         verify( disable_preempt_count > 0 );
     398        verify( !preemption_enabled );
     399        suspend();
     400        verify( !preemption_enabled );
    399401
    400402        enable_interrupts( __cfaabi_dbg_ctx );
     
    407409        this_processor->finish.lock_count  = count;
    408410
    409         verify( disable_preempt_count > 0 );
    410         suspend();
    411         verify( disable_preempt_count > 0 );
     411        verify( !preemption_enabled );
     412        suspend();
     413        verify( !preemption_enabled );
    412414
    413415        enable_interrupts( __cfaabi_dbg_ctx );
     
    422424        this_processor->finish.thrd_count  = thrd_count;
    423425
    424         verify( disable_preempt_count > 0 );
    425         suspend();
    426         verify( disable_preempt_count > 0 );
     426        verify( !preemption_enabled );
     427        suspend();
     428        verify( !preemption_enabled );
    427429
    428430        enable_interrupts( __cfaabi_dbg_ctx );
     
    430432
    431433void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    432         verify( disable_preempt_count > 0 );
     434        verify( !preemption_enabled );
    433435        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    434436        this_processor->finish.lock        = lock;
Note: See TracChangeset for help on using the changeset viewer.