Ignore:
File:
1 edited

Legend:

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

    r65deb18 rd0a045c7  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:33:18 2017
    13 // Update Count     : 2
     12// Last Modified On : Fri Dec  8 16:23:33 2017
     13// Update Count     : 3
    1414//
    1515
    1616//C Includes
    1717#include <stddef.h>
     18#define ftype `ftype`
    1819extern "C" {
    1920#include <stdio.h>
     
    2324#include <unistd.h>
    2425}
     26#undef ftype
    2527
    2628//CFA Includes
     
    5759
    5860volatile thread_local bool preemption_in_progress = 0;
     61volatile thread_local bool preemption_enabled = false;
    5962volatile thread_local unsigned short disable_preempt_count = 1;
    6063
     
    194197                        if(readyThread)
    195198                        {
    196                                 verify( disable_preempt_count > 0 );
     199                                verify( !preemption_enabled );
    197200
    198201                                runThread(this, readyThread);
    199202
    200                                 verify( disable_preempt_count > 0 );
     203                                verify( !preemption_enabled );
    201204
    202205                                //Some actions need to be taken from the kernel
     
    240243void finishRunning(processor * this) with( this->finish ) {
    241244        if( action_code == Release ) {
     245                verify( !preemption_enabled );
    242246                unlock( *lock );
    243247        }
     
    246250        }
    247251        else if( action_code == Release_Schedule ) {
     252                verify( !preemption_enabled );
    248253                unlock( *lock );
    249254                ScheduleThread( thrd );
    250255        }
    251256        else if( action_code == Release_Multi ) {
     257                verify( !preemption_enabled );
    252258                for(int i = 0; i < lock_count; i++) {
    253259                        unlock( *locks[i] );
     
    281287        this_coroutine = NULL;
    282288        this_thread = NULL;
     289        preemption_enabled = false;
    283290        disable_preempt_count = 1;
    284291        // SKULLDUGGERY: We want to create a context for the processor coroutine
     
    328335        verify( thrd->self_cor.state != Halted );
    329336
    330         verify( disable_preempt_count > 0 );
     337        verify( !preemption_enabled );
    331338
    332339        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    338345        }
    339346
    340         verify( disable_preempt_count > 0 );
     347        verify( !preemption_enabled );
    341348}
    342349
    343350thread_desc * nextThread(cluster * this) with( *this ) {
    344         verify( disable_preempt_count > 0 );
     351        verify( !preemption_enabled );
    345352        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    346353        thread_desc * head = pop_head( ready_queue );
    347354        unlock( ready_queue_lock );
    348         verify( disable_preempt_count > 0 );
     355        verify( !preemption_enabled );
    349356        return head;
    350357}
     
    352359void BlockInternal() {
    353360        disable_interrupts();
    354         verify( disable_preempt_count > 0 );
    355         suspend();
    356         verify( disable_preempt_count > 0 );
     361        verify( !preemption_enabled );
     362        suspend();
     363        verify( !preemption_enabled );
    357364        enable_interrupts( __cfaabi_dbg_ctx );
    358365}
     
    363370        this_processor->finish.lock        = lock;
    364371
    365         verify( disable_preempt_count > 0 );
    366         suspend();
    367         verify( disable_preempt_count > 0 );
     372        verify( !preemption_enabled );
     373        suspend();
     374        verify( !preemption_enabled );
    368375
    369376        enable_interrupts( __cfaabi_dbg_ctx );
     
    375382        this_processor->finish.thrd        = thrd;
    376383
    377         verify( disable_preempt_count > 0 );
    378         suspend();
    379         verify( disable_preempt_count > 0 );
     384        verify( !preemption_enabled );
     385        suspend();
     386        verify( !preemption_enabled );
    380387
    381388        enable_interrupts( __cfaabi_dbg_ctx );
     
    389396        this_processor->finish.thrd        = thrd;
    390397
    391         verify( disable_preempt_count > 0 );
    392         suspend();
    393         verify( disable_preempt_count > 0 );
     398        verify( !preemption_enabled );
     399        suspend();
     400        verify( !preemption_enabled );
    394401
    395402        enable_interrupts( __cfaabi_dbg_ctx );
     
    402409        this_processor->finish.lock_count  = count;
    403410
    404         verify( disable_preempt_count > 0 );
    405         suspend();
    406         verify( disable_preempt_count > 0 );
     411        verify( !preemption_enabled );
     412        suspend();
     413        verify( !preemption_enabled );
    407414
    408415        enable_interrupts( __cfaabi_dbg_ctx );
     
    417424        this_processor->finish.thrd_count  = thrd_count;
    418425
    419         verify( disable_preempt_count > 0 );
    420         suspend();
    421         verify( disable_preempt_count > 0 );
     426        verify( !preemption_enabled );
     427        suspend();
     428        verify( !preemption_enabled );
    422429
    423430        enable_interrupts( __cfaabi_dbg_ctx );
     
    425432
    426433void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    427         verify( disable_preempt_count > 0 );
     434        verify( !preemption_enabled );
    428435        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    429436        this_processor->finish.lock        = lock;
     
    513520        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
    514521}
     522
     523//=============================================================================================
     524// Unexpected Terminating logic
     525//=============================================================================================
     526
    515527
    516528static __spinlock_t kernel_abort_lock;
     
    609621}
    610622
     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)
    611656// Local Variables: //
    612657// mode: c //
Note: See TracChangeset for help on using the changeset viewer.