Ignore:
File:
1 edited

Legend:

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

    rb69ea6b rc40e7c5  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  8 23:52:19 2018
    13 // Update Count     : 5
     12// Last Modified On : Tue Feb  6 21:51:26 2018
     13// Update Count     : 4
    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
     
    5658thread_local processor *      volatile this_processor;
    5759
    58 // volatile thread_local bool preemption_in_progress = 0;
    59 // volatile thread_local bool preemption_enabled = false;
    60 // volatile thread_local unsigned short disable_preempt_count = 1;
    61 
    62 volatile thread_local __cfa_kernel_preemption_data_t preemption = { false, false, 1 };
     60volatile thread_local bool preemption_in_progress = 0;
     61volatile thread_local bool preemption_enabled = false;
     62volatile thread_local unsigned short disable_preempt_count = 1;
    6363
    6464//-----------------------------------------------------------------------------
     
    209209                        if(readyThread)
    210210                        {
    211                                 verify( !preemption.enabled );
     211                                verify( !preemption_enabled );
    212212
    213213                                runThread(this, readyThread);
    214214
    215                                 verify( !preemption.enabled );
     215                                verify( !preemption_enabled );
    216216
    217217                                //Some actions need to be taken from the kernel
     
    262262void finishRunning(processor * this) with( this->finish ) {
    263263        if( action_code == Release ) {
    264                 verify( !preemption.enabled );
     264                verify( !preemption_enabled );
    265265                unlock( *lock );
    266266        }
     
    269269        }
    270270        else if( action_code == Release_Schedule ) {
    271                 verify( !preemption.enabled );
     271                verify( !preemption_enabled );
    272272                unlock( *lock );
    273273                ScheduleThread( thrd );
    274274        }
    275275        else if( action_code == Release_Multi ) {
    276                 verify( !preemption.enabled );
     276                verify( !preemption_enabled );
    277277                for(int i = 0; i < lock_count; i++) {
    278278                        unlock( *locks[i] );
     
    306306        this_coroutine = NULL;
    307307        this_thread = NULL;
    308         preemption.enabled = false;
    309         preemption.disable_count = 1;
     308        preemption_enabled = false;
     309        disable_preempt_count = 1;
    310310        // SKULLDUGGERY: We want to create a context for the processor coroutine
    311311        // which is needed for the 2-step context switch. However, there is no reason
     
    347347}
    348348
    349 void kernel_first_resume(processor * this) {
    350         coroutine_desc * src = this_coroutine;
    351         coroutine_desc * dst = get_coroutine(*this->runner);
    352 
    353         verify( !preemption.enabled );
    354 
    355         create_stack(&dst->stack, dst->stack.size);
    356         CtxStart(this->runner, CtxInvokeCoroutine);
    357 
    358         verify( !preemption.enabled );
    359 
    360         dst->last = src;
    361         dst->starter = dst->starter ? dst->starter : src;
    362 
    363         // set state of current coroutine to inactive
    364         src->state = src->state == Halted ? Halted : Inactive;
    365 
    366         // set new coroutine that task is executing
    367         this_coroutine = dst;
    368 
    369         // SKULLDUGGERY normally interrupts are enable before leaving a coroutine ctxswitch.
    370         // Therefore, when first creating a coroutine, interrupts are enable before calling the main.
    371         // This is consistent with thread creation. However, when creating the main processor coroutine,
    372         // we wan't interrupts to be disabled. Therefore, we double-disable interrupts here so they will
    373         // stay disabled.
    374         disable_interrupts();
    375 
    376         // context switch to specified coroutine
    377         assert( src->stack.context );
    378         CtxSwitch( src->stack.context, dst->stack.context );
    379         // when CtxSwitch returns we are back in the src coroutine
    380 
    381         // set state of new coroutine to active
    382         src->state = Active;
    383 
    384         verify( !preemption.enabled );
    385 }
    386 
    387349//-----------------------------------------------------------------------------
    388350// Scheduler routines
     
    392354        verify( thrd->self_cor.state != Halted );
    393355
    394         verify( !preemption.enabled );
     356        verify( !preemption_enabled );
    395357
    396358        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    402364        }
    403365
    404         verify( !preemption.enabled );
     366        verify( !preemption_enabled );
    405367}
    406368
    407369thread_desc * nextThread(cluster * this) with( *this ) {
    408         verify( !preemption.enabled );
     370        verify( !preemption_enabled );
    409371        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    410372        thread_desc * head = pop_head( ready_queue );
    411373        unlock( ready_queue_lock );
    412         verify( !preemption.enabled );
     374        verify( !preemption_enabled );
    413375        return head;
    414376}
     
    416378void BlockInternal() {
    417379        disable_interrupts();
    418         verify( !preemption.enabled );
    419         returnToKernel();
    420         verify( !preemption.enabled );
     380        verify( !preemption_enabled );
     381        returnToKernel();
     382        verify( !preemption_enabled );
    421383        enable_interrupts( __cfaabi_dbg_ctx );
    422384}
     
    427389        this_processor->finish.lock        = lock;
    428390
    429         verify( !preemption.enabled );
    430         returnToKernel();
    431         verify( !preemption.enabled );
     391        verify( !preemption_enabled );
     392        returnToKernel();
     393        verify( !preemption_enabled );
    432394
    433395        enable_interrupts( __cfaabi_dbg_ctx );
     
    439401        this_processor->finish.thrd        = thrd;
    440402
    441         verify( !preemption.enabled );
    442         returnToKernel();
    443         verify( !preemption.enabled );
     403        verify( !preemption_enabled );
     404        returnToKernel();
     405        verify( !preemption_enabled );
    444406
    445407        enable_interrupts( __cfaabi_dbg_ctx );
     
    453415        this_processor->finish.thrd        = thrd;
    454416
    455         verify( !preemption.enabled );
    456         returnToKernel();
    457         verify( !preemption.enabled );
     417        verify( !preemption_enabled );
     418        returnToKernel();
     419        verify( !preemption_enabled );
    458420
    459421        enable_interrupts( __cfaabi_dbg_ctx );
     
    466428        this_processor->finish.lock_count  = count;
    467429
    468         verify( !preemption.enabled );
    469         returnToKernel();
    470         verify( !preemption.enabled );
     430        verify( !preemption_enabled );
     431        returnToKernel();
     432        verify( !preemption_enabled );
    471433
    472434        enable_interrupts( __cfaabi_dbg_ctx );
     
    481443        this_processor->finish.thrd_count  = thrd_count;
    482444
    483         verify( !preemption.enabled );
    484         returnToKernel();
    485         verify( !preemption.enabled );
     445        verify( !preemption_enabled );
     446        returnToKernel();
     447        verify( !preemption_enabled );
    486448
    487449        enable_interrupts( __cfaabi_dbg_ctx );
     
    489451
    490452void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    491         verify( !preemption.enabled );
     453        verify( !preemption_enabled );
    492454        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    493455        this_processor->finish.lock        = lock;
     
    503465// Kernel boot procedures
    504466void kernel_startup(void) {
    505         verify( !preemption.enabled );
    506467        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    507468
     
    541502        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    542503        // mainThread is on the ready queue when this call is made.
    543         kernel_first_resume( this_processor );
     504        resume( *mainProcessor->runner );
    544505
    545506
     
    548509        __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
    549510
    550         verify( !preemption.enabled );
    551511        enable_interrupts( __cfaabi_dbg_ctx );
    552         verify( preemption.enabled );
    553512}
    554513
     
    556515        __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
    557516
    558         verify( preemption.enabled );
    559517        disable_interrupts();
    560         verify( !preemption.enabled );
    561518
    562519        // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
Note: See TracChangeset for help on using the changeset viewer.