Ignore:
Timestamp:
Nov 30, 2017, 3:05:25 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
557435e, 5da9d6a
Parents:
dd9b59e (diff), c2b9f21 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa/concurrency
Files:
8 edited

Legend:

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

    rdd9b59e r3d560060  
    2323}
    2424
    25 #include "libhdr.h"
    26 
    2725#include "alarm.h"
    2826#include "kernel_private.h"
     
    110108}
    111109
    112 LIB_DEBUG_DO( bool validate( alarm_list_t * this ) {
     110__cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) {
    113111        alarm_node_t ** it = &this->head;
    114112        while( (*it) ) {
     
    186184
    187185        disable_interrupts();
    188         lock( event_kernel->lock DEBUG_CTX2 );
     186        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    189187        {
    190188                verify( validate( alarms ) );
     
    198196        unlock( event_kernel->lock );
    199197        this->set = true;
    200         enable_interrupts( DEBUG_CTX );
     198        enable_interrupts( __cfaabi_dbg_ctx );
    201199}
    202200
    203201void unregister_self( alarm_node_t * this ) {
    204202        disable_interrupts();
    205         lock( event_kernel->lock DEBUG_CTX2 );
     203        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    206204        {
    207205                verify( validate( &event_kernel->alarms ) );
     
    209207        }
    210208        unlock( event_kernel->lock );
    211         enable_interrupts( DEBUG_CTX );
     209        enable_interrupts( __cfaabi_dbg_ctx );
    212210        this->set = false;
    213211}
  • src/libcfa/concurrency/coroutine.c

    rdd9b59e r3d560060  
    2929#define __CFA_INVOKE_PRIVATE__
    3030#include "invoke.h"
    31 
    3231
    3332//-----------------------------------------------------------------------------
     
    7675void ^?{}(coStack_t & this) {
    7776        if ( ! this.userStack && this.storage ) {
    78                 LIB_DEBUG_DO(
     77                __cfaabi_dbg_debug_do(
    7978                        if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
    8079                                abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
     
    131130
    132131                // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment
    133                 LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );
    134                 LIB_NO_DEBUG_DO( this->storage = malloc( cxtSize + this->size + 8 ) );
     132                __cfaabi_dbg_debug_do( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );
     133                __cfaabi_dbg_no_debug_do( this->storage = malloc( cxtSize + this->size + 8 ) );
    135134
    136                 LIB_DEBUG_DO(
     135                __cfaabi_dbg_debug_do(
    137136                        if ( mprotect( this->storage, pageSize, PROT_NONE ) == -1 ) {
    138137                                abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
     
    144143                } // if
    145144
    146                 LIB_DEBUG_DO( this->limit = (char *)this->storage + pageSize );
    147                 LIB_NO_DEBUG_DO( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment
     145                __cfaabi_dbg_debug_do( this->limit = (char *)this->storage + pageSize );
     146                __cfaabi_dbg_no_debug_do( this->limit = (char *)libCeiling( (unsigned long)this->storage, 16 ) ); // minimum alignment
    148147
    149148        } else {
  • src/libcfa/concurrency/invoke.c

    rdd9b59e r3d560060  
    1818#include <stdio.h>
    1919
    20 #include "libhdr.h"
    2120#include "invoke.h"
    2221
     
    3130extern void __leave_thread_monitor( struct thread_desc * this );
    3231extern void disable_interrupts();
    33 extern void enable_interrupts( DEBUG_CTX_PARAM );
     32extern void enable_interrupts( __cfaabi_dbg_ctx_param );
    3433
    3534void CtxInvokeCoroutine(
    36       void (*main)(void *),
    37       struct coroutine_desc *(*get_coroutine)(void *),
    38       void *this
     35        void (*main)(void *),
     36        struct coroutine_desc *(*get_coroutine)(void *),
     37        void *this
    3938) {
    40       // LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
     39        struct coroutine_desc* cor = get_coroutine( this );
    4140
    42       struct coroutine_desc* cor = get_coroutine( this );
     41        if(cor->state == Primed) {
     42                __suspend_internal();
     43        }
    4344
    44       if(cor->state == Primed) {
    45             __suspend_internal();
    46       }
     45        cor->state = Active;
    4746
    48       cor->state = Active;
     47        main( this );
    4948
    50       main( this );
     49        cor->state = Halted;
    5150
    52       cor->state = Halted;
    53 
    54       //Final suspend, should never return
    55       __leave_coroutine();
    56       abortf("Resumed dead coroutine");
     51        //Final suspend, should never return
     52        __leave_coroutine();
     53        abortf("Resumed dead coroutine");
    5754}
    5855
    5956void CtxInvokeThread(
    60       void (*dtor)(void *),
    61       void (*main)(void *),
    62       struct thread_desc *(*get_thread)(void *),
    63       void *this
     57        void (*dtor)(void *),
     58        void (*main)(void *),
     59        struct thread_desc *(*get_thread)(void *),
     60        void *this
    6461) {
    65       // First suspend, once the thread arrives here,
    66       // the function pointer to main can be invalidated without risk
    67       __suspend_internal();
     62        // First suspend, once the thread arrives here,
     63        // the function pointer to main can be invalidated without risk
     64        __suspend_internal();
    6865
    69       // Fetch the thread handle from the user defined thread structure
    70       struct thread_desc* thrd = get_thread( this );
     66        // Fetch the thread handle from the user defined thread structure
     67        struct thread_desc* thrd = get_thread( this );
    7168
    72       // Officially start the thread by enabling preemption
    73       enable_interrupts( DEBUG_CTX );
     69        // Officially start the thread by enabling preemption
     70        enable_interrupts( __cfaabi_dbg_ctx );
    7471
    75       // Call the main of the thread
    76       main( this );
     72        // Call the main of the thread
     73        main( this );
    7774
    78       // To exit a thread we must :
    79       // 1 - Mark it as halted
    80       // 2 - Leave its monitor
    81       // 3 - Disable the interupts
    82       // 4 - Final suspend
    83       // The order of these 4 operations is very important
    84       //Final suspend, should never return
    85       __leave_thread_monitor( thrd );
    86       abortf("Resumed dead thread");
     75        // To exit a thread we must :
     76        // 1 - Mark it as halted
     77        // 2 - Leave its monitor
     78        // 3 - Disable the interupts
     79        // 4 - Final suspend
     80        // The order of these 4 operations is very important
     81        //Final suspend, should never return
     82        __leave_thread_monitor( thrd );
     83        abortf("Resumed dead thread");
    8784}
    8885
    8986
    9087void CtxStart(
    91       void (*main)(void *),
    92       struct coroutine_desc *(*get_coroutine)(void *),
    93       void *this,
    94       void (*invoke)(void *)
     88        void (*main)(void *),
     89        struct coroutine_desc *(*get_coroutine)(void *),
     90        void *this,
     91        void (*invoke)(void *)
    9592) {
    96       // LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p) to invoke (%p) from start (%p)\n", this, main, invoke, CtxStart);
    97 
    98       struct coStack_t* stack = &get_coroutine( this )->stack;
     93        struct coStack_t* stack = &get_coroutine( this )->stack;
    9994
    10095#if defined( __i386__ )
     
    10398            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    10499            uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
    105           uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
     100            uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
    106101            void *rturn;                          // where to go on return from uSwitch
    107102            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     
    116111        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    117112        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
    118       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    119       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     113        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     114        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    120115
    121116#elif defined( __x86_64__ )
    122117
    123       struct FakeStack {
    124             void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
    125             uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
    126             uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
    127             void *rturn;                        // where to go on return from uSwitch
    128             void *dummyReturn;                  // NULL return address to provide proper alignment
    129       };
     118        struct FakeStack {
     119                void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
     120                uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
     121                uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
     122                void *rturn;                        // where to go on return from uSwitch
     123                void *dummyReturn;                  // NULL return address to provide proper alignment
     124        };
    130125
    131       ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
    132       ((struct machine_context_t *)stack->context)->FP = NULL;          // terminate stack with NULL fp
     126        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     127        ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
    133128
    134       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
    135       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub;
    136       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;
    137       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
    138       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    139       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     129        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
     130        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = CtxInvokeStub;
     131        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;
     132        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
     133        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     134        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    140135#else
    141       #error Only __i386__ and __x86_64__ is supported for threads in cfa
     136        #error Only __i386__ and __x86_64__ is supported for threads in cfa
    142137#endif
    143138}
  • src/libcfa/concurrency/kernel.c

    rdd9b59e r3d560060  
    1414//
    1515
    16 #include "libhdr.h"
    17 
    1816//C Includes
    1917#include <stddef.h>
     
    150148
    151149        this.runner = &runner;
    152         LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);
     150        __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);
    153151        runner{ &this };
    154152}
     
    156154void ^?{}(processor & this) {
    157155        if( ! this.do_terminate ) {
    158                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);
     156                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    159157                this.do_terminate = true;
    160158                P( this.terminated );
     
    181179        processor * this = runner.proc;
    182180
    183         LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     181        __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this);
    184182
    185183        {
     
    187185                preemption_scope scope = { this };
    188186
    189                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
     187                __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
    190188
    191189                thread_desc * readyThread = NULL;
     
    213211                }
    214212
    215                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p stopping\n", this);
     213                __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this);
    216214        }
    217215
    218216        V( this->terminated );
    219217
    220         LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);
     218        __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this);
    221219}
    222220
     
    292290        processorCtx_t proc_cor_storage = { proc, &info };
    293291
    294         LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
     292        __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    295293
    296294        //Set global state
     
    299297
    300298        //We now have a proper context from which to schedule threads
    301         LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
     299        __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    302300
    303301        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     
    310308
    311309        // Main routine of the core returned, the core is now fully terminated
    312         LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
     310        __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner);
    313311
    314312        return NULL;
     
    316314
    317315void start(processor * this) {
    318         LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
     316        __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);
    319317
    320318        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    321319
    322         LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
     320        __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
    323321}
    324322
     
    334332        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    335333
    336         lock(   this_processor->cltr->ready_queue_lock DEBUG_CTX2 );
     334        lock(   this_processor->cltr->ready_queue_lock __cfaabi_dbg_ctx2 );
    337335        append( this_processor->cltr->ready_queue, thrd );
    338336        unlock( this_processor->cltr->ready_queue_lock );
     
    343341thread_desc * nextThread(cluster * this) {
    344342        verify( disable_preempt_count > 0 );
    345         lock( this->ready_queue_lock DEBUG_CTX2 );
     343        lock( this->ready_queue_lock __cfaabi_dbg_ctx2 );
    346344        thread_desc * head = pop_head( this->ready_queue );
    347345        unlock( this->ready_queue_lock );
     
    355353        suspend();
    356354        verify( disable_preempt_count > 0 );
    357         enable_interrupts( DEBUG_CTX );
     355        enable_interrupts( __cfaabi_dbg_ctx );
    358356}
    359357
     
    367365        verify( disable_preempt_count > 0 );
    368366
    369         enable_interrupts( DEBUG_CTX );
     367        enable_interrupts( __cfaabi_dbg_ctx );
    370368}
    371369
     
    381379        verify( disable_preempt_count > 0 );
    382380
    383         enable_interrupts( DEBUG_CTX );
     381        enable_interrupts( __cfaabi_dbg_ctx );
    384382}
    385383
     
    395393        verify( disable_preempt_count > 0 );
    396394
    397         enable_interrupts( DEBUG_CTX );
     395        enable_interrupts( __cfaabi_dbg_ctx );
    398396}
    399397
     
    408406        verify( disable_preempt_count > 0 );
    409407
    410         enable_interrupts( DEBUG_CTX );
     408        enable_interrupts( __cfaabi_dbg_ctx );
    411409}
    412410
     
    423421        verify( disable_preempt_count > 0 );
    424422
    425         enable_interrupts( DEBUG_CTX );
     423        enable_interrupts( __cfaabi_dbg_ctx );
    426424}
    427425
     
    441439// Kernel boot procedures
    442440void kernel_startup(void) {
    443         LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");
     441        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    444442
    445443        // Start by initializing the main thread
     
    450448        (*mainThread){ &info };
    451449
    452         LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     450        __cfaabi_dbg_print_safe("Kernel : Main thread ready\n");
    453451
    454452        // Initialize the main cluster
     
    456454        (*mainCluster){};
    457455
    458         LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
     456        __cfaabi_dbg_print_safe("Kernel : main cluster ready\n");
    459457
    460458        // Initialize the main processor and the main processor ctx
     
    483481
    484482        // THE SYSTEM IS NOW COMPLETELY RUNNING
    485         LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");
    486 
    487         enable_interrupts( DEBUG_CTX );
     483        __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
     484
     485        enable_interrupts( __cfaabi_dbg_ctx );
    488486}
    489487
    490488void kernel_shutdown(void) {
    491         LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");
     489        __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
    492490
    493491        disable_interrupts();
     
    513511        ^(mainThread){};
    514512
    515         LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");
     513        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
    516514}
    517515
     
    523521        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    524522        // the globalAbort flag is true.
    525         lock( kernel_abort_lock DEBUG_CTX2 );
     523        lock( kernel_abort_lock __cfaabi_dbg_ctx2 );
    526524
    527525        // first task to abort ?
     
    548546
    549547        int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd );
    550         __lib_debug_write( abort_text, len );
     548        __cfaabi_dbg_bits_write( abort_text, len );
    551549
    552550        if ( thrd != this_coroutine ) {
    553551                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine );
    554                 __lib_debug_write( abort_text, len );
     552                __cfaabi_dbg_bits_write( abort_text, len );
    555553        }
    556554        else {
    557                 __lib_debug_write( ".\n", 2 );
     555                __cfaabi_dbg_bits_write( ".\n", 2 );
    558556        }
    559557}
    560558
    561559extern "C" {
    562         void __lib_debug_acquire() {
    563                 lock( kernel_debug_lock DEBUG_CTX2 );
    564         }
    565 
    566         void __lib_debug_release() {
     560        void __cfaabi_dbg_bits_acquire() {
     561                lock( kernel_debug_lock __cfaabi_dbg_ctx2 );
     562        }
     563
     564        void __cfaabi_dbg_bits_release() {
    567565                unlock( kernel_debug_lock );
    568566        }
     
    582580
    583581void P(semaphore & this) {
    584         lock( this.lock DEBUG_CTX2 );
     582        lock( this.lock __cfaabi_dbg_ctx2 );
    585583        this.count -= 1;
    586584        if ( this.count < 0 ) {
     
    598596void V(semaphore & this) {
    599597        thread_desc * thrd = NULL;
    600         lock( this.lock DEBUG_CTX2 );
     598        lock( this.lock __cfaabi_dbg_ctx2 );
    601599        this.count += 1;
    602600        if ( this.count <= 0 ) {
  • src/libcfa/concurrency/kernel_private.h

    rdd9b59e r3d560060  
    1616#pragma once
    1717
    18 #include "libhdr.h"
    19 
    2018#include "kernel"
    2119#include "thread"
     
    3028        void disable_interrupts();
    3129        void enable_interrupts_noPoll();
    32         void enable_interrupts( DEBUG_CTX_PARAM );
     30        void enable_interrupts( __cfaabi_dbg_ctx_param );
    3331}
    3432
     
    3937        disable_interrupts();
    4038        ScheduleThread( thrd );
    41         enable_interrupts( DEBUG_CTX );
     39        enable_interrupts( __cfaabi_dbg_ctx );
    4240}
    4341thread_desc * nextThread(cluster * this);
  • src/libcfa/concurrency/monitor.c

    rdd9b59e r3d560060  
    1919#include <inttypes.h>
    2020
    21 #include "libhdr.h"
    2221#include "kernel_private.h"
    2322
     
    9190        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9291                // Lock the monitor spinlock
    93                 DO_LOCK( this->lock DEBUG_CTX2 );
     92                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    9493                thread_desc * thrd = this_thread;
    9594
    96                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     95                __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9796
    9897                if( !this->owner ) {
     
    10099                        set_owner( this, thrd );
    101100
    102                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon is free \n");
     101                        __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
    103102                }
    104103                else if( this->owner == thrd) {
     
    106105                        this->recursion += 1;
    107106
    108                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon already owned \n");
     107                        __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
    109108                }
    110109                else if( is_accepted( this, group) ) {
     
    115114                        reset_mask( this );
    116115
    117                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts \n");
     116                        __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
    118117                }
    119118                else {
    120                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     119                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    121120
    122121                        // Some one else has the monitor, wait in line for it
     
    124123                        BlockInternal( &this->lock );
    125124
    126                         LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     125                        __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    127126
    128127                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    130129                }
    131130
    132                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entered  mon %p\n", thrd, this);
     131                __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
    133132
    134133                // Release the lock and leave
     
    139138        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    140139                // Lock the monitor spinlock
    141                 DO_LOCK( this->lock DEBUG_CTX2 );
     140                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    142141                thread_desc * thrd = this_thread;
    143142
    144                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     143                __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    145144
    146145
    147146                if( !this->owner ) {
    148                         LIB_DEBUG_PRINT_SAFE("Kernel : Destroying free mon %p\n", this);
     147                        __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
    149148
    150149                        // No one has the monitor, just take it
     
    164163                __monitor_group_t group = { &this, 1, func };
    165164                if( is_accepted( this, group) ) {
    166                         LIB_DEBUG_PRINT_SAFE("Kernel :  mon accepts dtor, block and signal it \n");
     165                        __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
    167166
    168167                        // Wake the thread that is waiting for this
     
    183182                }
    184183                else {
    185                         LIB_DEBUG_PRINT_SAFE("Kernel :  blocking \n");
     184                        __cfaabi_dbg_print_safe("Kernel :  blocking \n");
    186185
    187186                        wait_ctx( this_thread, 0 )
     
    196195                }
    197196
    198                 LIB_DEBUG_PRINT_SAFE("Kernel : Destroying %p\n", this);
     197                __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
    199198
    200199        }
     
    203202        void __leave_monitor_desc( monitor_desc * this ) {
    204203                // Lock the monitor spinlock, DO_LOCK to reduce contention
    205                 DO_LOCK( this->lock DEBUG_CTX2 );
    206 
    207                 LIB_DEBUG_PRINT_SAFE("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     204                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     205
     206                __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    208207
    209208                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     
    215214                // it means we don't need to do anything
    216215                if( this->recursion != 0) {
    217                         LIB_DEBUG_PRINT_SAFE("Kernel :  recursion still %d\n", this->recursion);
     216                        __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
    218217                        unlock( this->lock );
    219218                        return;
     
    232231        // Leave single monitor for the last time
    233232        void __leave_dtor_monitor_desc( monitor_desc * this ) {
    234                 LIB_DEBUG_DO(
     233                __cfaabi_dbg_debug_do(
    235234                        if( this_thread != this->owner ) {
    236235                                abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     
    249248
    250249                // Lock the monitor now
    251                 DO_LOCK( this->lock DEBUG_CTX2 );
     250                DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
    252251
    253252                disable_interrupts();
     
    308307        (this_thread->monitors){m, count, func};
    309308
    310         // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     309        // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
    311310
    312311        // Enter the monitors in order
     
    314313        enter( group );
    315314
    316         // LIB_DEBUG_PRINT_SAFE("MGUARD : entered\n");
     315        // __cfaabi_dbg_print_safe("MGUARD : entered\n");
    317316}
    318317
     
    320319// Dtor for monitor guard
    321320void ^?{}( monitor_guard_t & this ) {
    322         // LIB_DEBUG_PRINT_SAFE("MGUARD : leaving %d\n", this.count);
     321        // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
    323322
    324323        // Leave the monitors in order
    325324        leave( this.m, this.count );
    326325
    327         // LIB_DEBUG_PRINT_SAFE("MGUARD : left\n");
     326        // __cfaabi_dbg_print_safe("MGUARD : left\n");
    328327
    329328        // Restore thread context
     
    430429
    431430        //Some more checking in debug
    432         LIB_DEBUG_DO(
     431        __cfaabi_dbg_debug_do(
    433432                thread_desc * this_thrd = this_thread;
    434433                if ( this.monitor_count != this_thrd->monitors.size ) {
     
    487486        set_owner( monitors, count, signallee );
    488487
    489         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
     488        __cfaabi_dbg_print_buffer_decl( "Kernel : signal_block condition %p (s: %p)\n", &this, signallee );
    490489
    491490        //Everything is ready to go to sleep
     
    496495
    497496
    498         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :   signal_block returned\n" );
     497        __cfaabi_dbg_print_buffer_local( "Kernel :   signal_block returned\n" );
    499498
    500499        //We are back, restore the masks and recursions
     
    535534        __lock_size_t actual_count = aggregate( mon_storage, mask );
    536535
    537         LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
     536        __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max);
    538537
    539538        if(actual_count == 0) return;
    540539
    541         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : waitfor internal proceeding\n");
     540        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
    542541
    543542        // Create storage for monitor context
     
    556555                        __acceptable_t& accepted = mask[index];
    557556                        if( accepted.is_dtor ) {
    558                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
     557                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
    559558                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    560559
     
    568567                        }
    569568                        else {
    570                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, baton-passing\n");
     569                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");
    571570
    572571                                // Create the node specific to this wait operation
     
    576575                                monitor_save;
    577576
    578                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel :  baton of %d monitors : ", count );
     577                                __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %d monitors : ", count );
    579578                                #ifdef __CFA_DEBUG_PRINT__
    580579                                        for( int i = 0; i < count; i++) {
    581                                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
     580                                                __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
    582581                                        }
    583582                                #endif
    584                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "\n");
     583                                __cfaabi_dbg_print_buffer_local( "\n");
    585584
    586585                                // Set the owners to be the next thread
     
    593592                                monitor_restore;
    594593
    595                                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : thread present, returned\n");
     594                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
    596595                        }
    597596
    598                         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     597                        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    599598                        return;
    600599                }
     
    603602
    604603        if( duration == 0 ) {
    605                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : non-blocking, exiting\n");
     604                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
    606605
    607606                unlock_all( locks, count );
    608607
    609                 LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     608                __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    610609                return;
    611610        }
     
    614613        verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    615614
    616         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : blocking waitfor\n");
     615        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
    617616
    618617        // Create the node specific to this wait operation
     
    636635        monitor_restore;
    637636
    638         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : exiting\n");
    639 
    640         LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
     637        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     638
     639        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
    641640}
    642641
     
    645644
    646645static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    647         // LIB_DEBUG_PRINT_SAFE("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     646        // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    648647
    649648        //Pass the monitor appropriately
     
    677676static inline thread_desc * next_thread( monitor_desc * this ) {
    678677        //Check the signaller stack
    679         LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     678        __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    680679        __condition_criterion_t * urgent = pop( this->signal_stack );
    681680        if( urgent ) {
     
    729728        for( __lock_size_t i = 0; i < count; i++) {
    730729                (criteria[i]){ monitors[i], waiter };
    731                 LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     730                __cfaabi_dbg_print_safe( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    732731                push( criteria[i].target->signal_stack, &criteria[i] );
    733732        }
     
    738737static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    739738        for( __lock_size_t i = 0; i < count; i++ ) {
    740                 DO_LOCK( *locks[i] DEBUG_CTX2 );
     739                DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
    741740        }
    742741}
     
    745744        for( __lock_size_t i = 0; i < count; i++ ) {
    746745                __spinlock_t * l = &source[i]->lock;
    747                 DO_LOCK( *l DEBUG_CTX2 );
     746                DO_LOCK( *l __cfaabi_dbg_ctx2 );
    748747                if(locks) locks[i] = l;
    749748        }
     
    803802        for(    int i = 0; i < count; i++ ) {
    804803
    805                 // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
     804                // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target );
    806805                if( &criteria[i] == target ) {
    807806                        criteria[i].ready = true;
    808                         // LIB_DEBUG_PRINT_SAFE( "True\n" );
     807                        // __cfaabi_dbg_print_safe( "True\n" );
    809808                }
    810809
     
    812811        }
    813812
    814         LIB_DEBUG_PRINT_SAFE( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
     813        __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : NULL );
    815814        return ready2run ? node->waiting_thread : NULL;
    816815}
     
    819818        thread_desc * thrd = this_thread;
    820819        if( !this.monitors ) {
    821                 // LIB_DEBUG_PRINT_SAFE("Branding\n");
     820                // __cfaabi_dbg_print_safe("Branding\n");
    822821                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    823822                this.monitor_count = thrd->monitors.size;
  • src/libcfa/concurrency/preemption.c

    rdd9b59e r3d560060  
    1414//
    1515
    16 #include "libhdr.h"
    1716#include "preemption.h"
    1817
     
    148147//=============================================================================================
    149148
    150 LIB_DEBUG_DO( static thread_local void * last_interrupt = 0; )
     149__cfaabi_dbg_debug_do( static thread_local void * last_interrupt = 0; )
    151150
    152151extern "C" {
     
    159158        // Enable interrupts by decrementing the counter
    160159        // If counter reaches 0, execute any pending CtxSwitch
    161         void enable_interrupts( DEBUG_CTX_PARAM ) {
     160        void enable_interrupts( __cfaabi_dbg_ctx_param ) {
    162161                processor * proc   = this_processor;      // Cache the processor now since interrupts can start happening after the atomic add
    163162                thread_desc * thrd = this_thread;         // Cache the thread now since interrupts can start happening after the atomic add
     
    173172
    174173                // For debugging purposes : keep track of the last person to enable the interrupts
    175                 LIB_DEBUG_DO( proc->last_enable = caller; )
     174                __cfaabi_dbg_debug_do( proc->last_enable = caller; )
    176175        }
    177176
     
    233232// Called from kernel_startup
    234233void kernel_start_preemption() {
    235         LIB_DEBUG_PRINT_SAFE("Kernel : Starting preemption\n");
     234        __cfaabi_dbg_print_safe("Kernel : Starting preemption\n");
    236235
    237236        // Start with preemption disabled until ready
     
    255254// Called from kernel_shutdown
    256255void kernel_stop_preemption() {
    257         LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n");
     256        __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");
    258257
    259258        // Block all signals since we are already shutting down
     
    271270        // Preemption is now fully stopped
    272271
    273         LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n");
     272        __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");
    274273}
    275274
     
    297296// Receives SIGUSR1 signal and causes the current thread to yield
    298297void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
    299         LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
     298        __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
    300299
    301300        // Check if it is safe to preempt here
     
    346345                assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
    347346
    348                 // LIB_DEBUG_PRINT_SAFE("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
     347                // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
    349348                // Switch on the code (a.k.a. the sender) to
    350349                switch( info.si_code )
     
    354353                case SI_TIMER:
    355354                case SI_KERNEL:
    356                         // LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n");
    357                         lock( event_kernel->lock DEBUG_CTX2 );
     355                        // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");
     356                        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    358357                        tick_preemption();
    359358                        unlock( event_kernel->lock );
     
    368367
    369368EXIT:
    370         LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n");
     369        __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");
    371370        return NULL;
    372371}
     
    380379
    381380        if ( sigaction( sig, &act, NULL ) == -1 ) {
    382                 LIB_DEBUG_PRINT_BUFFER_DECL(
     381                __cfaabi_dbg_print_buffer_decl(
    383382                        " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",
    384383                        sig, handler, flags, errno, strerror( errno )
     
    397396
    398397        if ( sigaction( sig, &act, NULL ) == -1 ) {
    399                 LIB_DEBUG_PRINT_BUFFER_DECL(
     398                __cfaabi_dbg_print_buffer_decl(
    400399                        " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n",
    401400                        sig, errno, strerror( errno )
     
    409408//=============================================================================================
    410409
    411 LIB_DEBUG_DO(
     410__cfaabi_dbg_debug_do(
    412411        static void __kernel_backtrace( int start ) {
    413412                // skip first N stack frames
     
    476475
    477476// void sigHandler_segv( __CFA_SIGPARMS__ ) {
    478 //      LIB_DEBUG_DO(
     477//      __cfaabi_dbg_debug_do(
    479478//              #ifdef __USE_STREAM__
    480479//              serr    | "*CFA runtime error* program cfa-cpp terminated with"
     
    493492// void sigHandler_abort( __CFA_SIGPARMS__ ) {
    494493//      // skip first 6 stack frames
    495 //      LIB_DEBUG_DO( __kernel_backtrace( 6 ); )
     494//      __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); )
    496495
    497496//      // reset default signal handler
  • src/libcfa/concurrency/thread.c

    rdd9b59e r3d560060  
    1717
    1818#include "kernel_private.h"
    19 #include "libhdr.h"
    2019
    2120#define __CFA_INVOKE_PRIVATE__
     
    7271        thrd_c->last = this_coroutine;
    7372
    74         // LIB_DEBUG_PRINT_SAFE("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
     73        // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
    7574
    7675        disable_interrupts();
     
    8281
    8382        ScheduleThread(thrd_h);
    84         enable_interrupts( DEBUG_CTX );
     83        enable_interrupts( __cfaabi_dbg_ctx );
    8584}
    8685
Note: See TracChangeset for help on using the changeset viewer.