Ignore:
File:
1 edited

Legend:

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

    rc2b9f21 r0cf5b79  
    1414//
    1515
     16#include "libhdr.h"
     17
    1618//C Includes
    1719#include <stddef.h>
     
    148150
    149151        this.runner = &runner;
    150         __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);
     152        LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);
    151153        runner{ &this };
    152154}
     
    154156void ^?{}(processor & this) {
    155157        if( ! this.do_terminate ) {
    156                 __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
     158                LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);
    157159                this.do_terminate = true;
    158160                P( this.terminated );
     
    179181        processor * this = runner.proc;
    180182
    181         __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this);
     183        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
    182184
    183185        {
     
    185187                preemption_scope scope = { this };
    186188
    187                 __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
     189                LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
    188190
    189191                thread_desc * readyThread = NULL;
     
    211213                }
    212214
    213                 __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this);
     215                LIB_DEBUG_PRINT_SAFE("Kernel : core %p stopping\n", this);
    214216        }
    215217
    216218        V( this->terminated );
    217219
    218         __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this);
     220        LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);
    219221}
    220222
     
    290292        processorCtx_t proc_cor_storage = { proc, &info };
    291293
    292         __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
     294        LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    293295
    294296        //Set global state
     
    297299
    298300        //We now have a proper context from which to schedule threads
    299         __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
     301        LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    300302
    301303        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     
    308310
    309311        // Main routine of the core returned, the core is now fully terminated
    310         __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner);
     312        LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
    311313
    312314        return NULL;
     
    314316
    315317void start(processor * this) {
    316         __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);
     318        LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
    317319
    318320        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    319321
    320         __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
     322        LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
    321323}
    322324
     
    332334        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    333335
    334         lock(   this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 );
     336        lock(   this_processor->cltr->ready_queue_lock DEBUG_CTX2 );
    335337        append( this_processor->cltr->ready_queue, thrd );
    336338        unlock( this_processor->cltr->ready_queue_lock );
     
    341343thread_desc * nextThread(cluster * this) {
    342344        verify( disable_preempt_count > 0 );
    343         lock( this->ready_queue_lock __cfaabi_dbg_ctx2 );
     345        lock( this->ready_queue_lock DEBUG_CTX2 );
    344346        thread_desc * head = pop_head( this->ready_queue );
    345347        unlock( this->ready_queue_lock );
     
    353355        suspend();
    354356        verify( disable_preempt_count > 0 );
    355         enable_interrupts( __cfaabi_dbg_ctx );
     357        enable_interrupts( DEBUG_CTX );
    356358}
    357359
     
    365367        verify( disable_preempt_count > 0 );
    366368
    367         enable_interrupts( __cfaabi_dbg_ctx );
     369        enable_interrupts( DEBUG_CTX );
    368370}
    369371
     
    379381        verify( disable_preempt_count > 0 );
    380382
    381         enable_interrupts( __cfaabi_dbg_ctx );
     383        enable_interrupts( DEBUG_CTX );
    382384}
    383385
     
    393395        verify( disable_preempt_count > 0 );
    394396
    395         enable_interrupts( __cfaabi_dbg_ctx );
     397        enable_interrupts( DEBUG_CTX );
    396398}
    397399
     
    406408        verify( disable_preempt_count > 0 );
    407409
    408         enable_interrupts( __cfaabi_dbg_ctx );
     410        enable_interrupts( DEBUG_CTX );
    409411}
    410412
     
    421423        verify( disable_preempt_count > 0 );
    422424
    423         enable_interrupts( __cfaabi_dbg_ctx );
     425        enable_interrupts( DEBUG_CTX );
    424426}
    425427
     
    439441// Kernel boot procedures
    440442void kernel_startup(void) {
    441         __cfaabi_dbg_print_safe("Kernel : Starting\n");
     443        LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");
    442444
    443445        // Start by initializing the main thread
     
    448450        (*mainThread){ &info };
    449451
    450         __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
     452        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
    451453
    452454        // Initialize the main cluster
     
    454456        (*mainCluster){};
    455457
    456         __cfaabi_dbg_print_safe("Kernel : main cluster ready\n");
     458        LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
    457459
    458460        // Initialize the main processor and the main processor ctx
     
    481483
    482484        // THE SYSTEM IS NOW COMPLETELY RUNNING
    483         __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
    484 
    485         enable_interrupts( __cfaabi_dbg_ctx );
     485        LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");
     486
     487        enable_interrupts( DEBUG_CTX );
    486488}
    487489
    488490void kernel_shutdown(void) {
    489         __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
     491        LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");
    490492
    491493        disable_interrupts();
     
    511513        ^(mainThread){};
    512514
    513         __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
     515        LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");
    514516}
    515517
     
    521523        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    522524        // the globalAbort flag is true.
    523         lock( kernel_abort_lock __cfaabi_dbg_ctx2 );
     525        lock( kernel_abort_lock DEBUG_CTX2 );
    524526
    525527        // first task to abort ?
     
    546548
    547549        int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd );
    548         __cfaabi_dbg_bits_write( abort_text, len );
     550        __lib_debug_write( abort_text, len );
    549551
    550552        if ( thrd != this_coroutine ) {
    551553                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine );
    552                 __cfaabi_dbg_bits_write( abort_text, len );
     554                __lib_debug_write( abort_text, len );
    553555        }
    554556        else {
    555                 __cfaabi_dbg_bits_write( ".\n", 2 );
     557                __lib_debug_write( ".\n", 2 );
    556558        }
    557559}
    558560
    559561extern "C" {
    560         void __cfaabi_dbg_bits_acquire() {
    561                 lock( kernel_debug_lock __cfaabi_dbg_ctx2 );
    562         }
    563 
    564         void __cfaabi_dbg_bits_release() {
     562        void __lib_debug_acquire() {
     563                lock( kernel_debug_lock DEBUG_CTX2 );
     564        }
     565
     566        void __lib_debug_release() {
    565567                unlock( kernel_debug_lock );
    566568        }
     
    580582
    581583void P(semaphore & this) {
    582         lock( this.lock __cfaabi_dbg_ctx2 );
     584        lock( this.lock DEBUG_CTX2 );
    583585        this.count -= 1;
    584586        if ( this.count < 0 ) {
     
    596598void V(semaphore & this) {
    597599        thread_desc * thrd = NULL;
    598         lock( this.lock __cfaabi_dbg_ctx2 );
     600        lock( this.lock DEBUG_CTX2 );
    599601        this.count += 1;
    600602        if ( this.count <= 0 ) {
Note: See TracChangeset for help on using the changeset viewer.