Ignore:
File:
1 edited

Legend:

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

    rd0a045c7 r65deb18  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec  8 16:23:33 2017
    13 // Update Count     : 3
     12// Last Modified On : Fri Jul 21 22:33:18 2017
     13// Update Count     : 2
    1414//
    1515
    1616//C Includes
    1717#include <stddef.h>
    18 #define ftype `ftype`
    1918extern "C" {
    2019#include <stdio.h>
     
    2423#include <unistd.h>
    2524}
    26 #undef ftype
    2725
    2826//CFA Includes
     
    5957
    6058volatile thread_local bool preemption_in_progress = 0;
    61 volatile thread_local bool preemption_enabled = false;
    6259volatile thread_local unsigned short disable_preempt_count = 1;
    6360
     
    197194                        if(readyThread)
    198195                        {
    199                                 verify( !preemption_enabled );
     196                                verify( disable_preempt_count > 0 );
    200197
    201198                                runThread(this, readyThread);
    202199
    203                                 verify( !preemption_enabled );
     200                                verify( disable_preempt_count > 0 );
    204201
    205202                                //Some actions need to be taken from the kernel
     
    243240void finishRunning(processor * this) with( this->finish ) {
    244241        if( action_code == Release ) {
    245                 verify( !preemption_enabled );
    246242                unlock( *lock );
    247243        }
     
    250246        }
    251247        else if( action_code == Release_Schedule ) {
    252                 verify( !preemption_enabled );
    253248                unlock( *lock );
    254249                ScheduleThread( thrd );
    255250        }
    256251        else if( action_code == Release_Multi ) {
    257                 verify( !preemption_enabled );
    258252                for(int i = 0; i < lock_count; i++) {
    259253                        unlock( *locks[i] );
     
    287281        this_coroutine = NULL;
    288282        this_thread = NULL;
    289         preemption_enabled = false;
    290283        disable_preempt_count = 1;
    291284        // SKULLDUGGERY: We want to create a context for the processor coroutine
     
    335328        verify( thrd->self_cor.state != Halted );
    336329
    337         verify( !preemption_enabled );
     330        verify( disable_preempt_count > 0 );
    338331
    339332        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    345338        }
    346339
    347         verify( !preemption_enabled );
     340        verify( disable_preempt_count > 0 );
    348341}
    349342
    350343thread_desc * nextThread(cluster * this) with( *this ) {
    351         verify( !preemption_enabled );
     344        verify( disable_preempt_count > 0 );
    352345        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    353346        thread_desc * head = pop_head( ready_queue );
    354347        unlock( ready_queue_lock );
    355         verify( !preemption_enabled );
     348        verify( disable_preempt_count > 0 );
    356349        return head;
    357350}
     
    359352void BlockInternal() {
    360353        disable_interrupts();
    361         verify( !preemption_enabled );
    362         suspend();
    363         verify( !preemption_enabled );
     354        verify( disable_preempt_count > 0 );
     355        suspend();
     356        verify( disable_preempt_count > 0 );
    364357        enable_interrupts( __cfaabi_dbg_ctx );
    365358}
     
    370363        this_processor->finish.lock        = lock;
    371364
    372         verify( !preemption_enabled );
    373         suspend();
    374         verify( !preemption_enabled );
     365        verify( disable_preempt_count > 0 );
     366        suspend();
     367        verify( disable_preempt_count > 0 );
    375368
    376369        enable_interrupts( __cfaabi_dbg_ctx );
     
    382375        this_processor->finish.thrd        = thrd;
    383376
    384         verify( !preemption_enabled );
    385         suspend();
    386         verify( !preemption_enabled );
     377        verify( disable_preempt_count > 0 );
     378        suspend();
     379        verify( disable_preempt_count > 0 );
    387380
    388381        enable_interrupts( __cfaabi_dbg_ctx );
     
    396389        this_processor->finish.thrd        = thrd;
    397390
    398         verify( !preemption_enabled );
    399         suspend();
    400         verify( !preemption_enabled );
     391        verify( disable_preempt_count > 0 );
     392        suspend();
     393        verify( disable_preempt_count > 0 );
    401394
    402395        enable_interrupts( __cfaabi_dbg_ctx );
     
    409402        this_processor->finish.lock_count  = count;
    410403
    411         verify( !preemption_enabled );
    412         suspend();
    413         verify( !preemption_enabled );
     404        verify( disable_preempt_count > 0 );
     405        suspend();
     406        verify( disable_preempt_count > 0 );
    414407
    415408        enable_interrupts( __cfaabi_dbg_ctx );
     
    424417        this_processor->finish.thrd_count  = thrd_count;
    425418
    426         verify( !preemption_enabled );
    427         suspend();
    428         verify( !preemption_enabled );
     419        verify( disable_preempt_count > 0 );
     420        suspend();
     421        verify( disable_preempt_count > 0 );
    429422
    430423        enable_interrupts( __cfaabi_dbg_ctx );
     
    432425
    433426void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    434         verify( !preemption_enabled );
     427        verify( disable_preempt_count > 0 );
    435428        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    436429        this_processor->finish.lock        = lock;
     
    520513        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
    521514}
    522 
    523 //=============================================================================================
    524 // Unexpected Terminating logic
    525 //=============================================================================================
    526 
    527515
    528516static __spinlock_t kernel_abort_lock;
     
    621609}
    622610
    623 //-----------------------------------------------------------------------------
    624 // Debug
    625 __cfaabi_dbg_debug_do(
    626         struct {
    627                 thread_desc * tail;
    628         } __cfaabi_dbg_thread_list = { NULL };
    629 
    630         void __cfaabi_dbg_thread_register( thread_desc * thrd ) {
    631                 if( !__cfaabi_dbg_thread_list.tail ) {
    632                         __cfaabi_dbg_thread_list.tail = thrd;
    633                         return;
    634                 }
    635                 __cfaabi_dbg_thread_list.tail->dbg_next = thrd;
    636                 thrd->dbg_prev = __cfaabi_dbg_thread_list.tail;
    637                 __cfaabi_dbg_thread_list.tail = thrd;
    638         }
    639 
    640         void __cfaabi_dbg_thread_unregister( thread_desc * thrd ) {
    641                 thread_desc * prev = thrd->dbg_prev;
    642                 thread_desc * next = thrd->dbg_next;
    643 
    644                 if( next ) { next->dbg_prev = prev; }
    645                 else       {
    646                         assert( __cfaabi_dbg_thread_list.tail == thrd );
    647                         __cfaabi_dbg_thread_list.tail = prev;
    648                 }
    649 
    650                 if( prev ) { prev->dbg_next = next; }
    651 
    652                 thrd->dbg_prev = NULL;
    653                 thrd->dbg_next = NULL;
    654         }
    655 )
    656611// Local Variables: //
    657612// mode: c //
Note: See TracChangeset for help on using the changeset viewer.