Ignore:
Timestamp:
Mar 31, 2017, 12:24:39 PM (7 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:
5ea06d6
Parents:
72dc82a (diff), 077810d (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 branches 'master' and 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa/concurrency
Files:
2 edited

Legend:

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

    r72dc82a r78d3dd5  
    1515//
    1616
     17#include "startup.h"
     18
    1719//Start and stop routine for the kernel, declared first to make sure they run first
    18 void kernel_startup(void)  __attribute__((constructor(101)));
    19 void kernel_shutdown(void) __attribute__((destructor(101)));
     20void kernel_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) ));
     21void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL ) ));
    2022
    2123//Header
     
    2527#include <stddef.h>
    2628extern "C" {
     29#include <stdio.h>
    2730#include <fenv.h>
    2831#include <sys/resource.h>
     32#include <signal.h>
     33#include <unistd.h>
    2934}
    3035
     
    146151
    147152        this->runner = runner;
    148         LIB_DEBUG_PRINTF("Kernel : constructing processor context %p\n", runner);
     153        LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner);
    149154        runner{ this };
    150155}
     
    152157void ^?{}(processor * this) {
    153158        if( ! this->is_terminated ) {
    154                 LIB_DEBUG_PRINTF("Kernel : core %p signaling termination\n", this);
     159                LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this);
    155160                this->is_terminated = true;
    156161                wait( &this->terminated );
     
    173178void main(processorCtx_t * runner) {
    174179        processor * this = runner->proc;
    175         LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this);
     180        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
    176181
    177182        thread_desc * readyThread = NULL;
     
    195200        }
    196201
    197         LIB_DEBUG_PRINTF("Kernel : core %p unlocking thread\n", this);
     202        LIB_DEBUG_PRINT_SAFE("Kernel : core %p unlocking thread\n", this);
    198203        signal( &this->terminated );
    199         LIB_DEBUG_PRINTF("Kernel : core %p terminated\n", this);
     204        LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);
    200205}
    201206
     
    255260        processorCtx_t proc_cor_storage = { proc, &info };
    256261
    257         LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
     262        LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    258263
    259264        //Set global state
     
    262267
    263268        //We now have a proper context from which to schedule threads
    264         LIB_DEBUG_PRINTF("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
     269        LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    265270
    266271        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     
    273278
    274279        // Main routine of the core returned, the core is now fully terminated
    275         LIB_DEBUG_PRINTF("Kernel : core %p main ended (%p)\n", proc, proc->runner);     
     280        LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
    276281
    277282        return NULL;
     
    279284
    280285void start(processor * this) {
    281         LIB_DEBUG_PRINTF("Kernel : Starting core %p\n", this);
     286        LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
    282287       
    283288        // pthread_attr_t attributes;
     
    288293        // pthread_attr_destroy( &attributes );
    289294
    290         LIB_DEBUG_PRINTF("Kernel : core %p started\n", this);   
     295        LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);       
    291296}
    292297
     
    336341// Kernel boot procedures
    337342void kernel_startup(void) {
    338         LIB_DEBUG_PRINTF("Kernel : Starting\n");       
     343        LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");   
    339344
    340345        // Start by initializing the main thread
     
    371376
    372377        // THE SYSTEM IS NOW COMPLETELY RUNNING
    373         LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n");
     378        LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");
    374379}
    375380
    376381void kernel_shutdown(void) {
    377         LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down\n");
     382        LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");
    378383
    379384        // SKULLDUGGERY: Notify the systemProcessor it needs to terminates.
     
    394399        ^(mainThread){};
    395400
    396         LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n");       
     401        LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");   
     402}
     403
     404static spinlock kernel_abort_lock;
     405static spinlock kernel_debug_lock;
     406static bool kernel_abort_called = false;
     407
     408void * kernel_abort    (void) __attribute__ ((__nothrow__)) {
     409        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
     410        // the globalAbort flag is true.
     411        lock( &kernel_abort_lock );
     412
     413        // first task to abort ?
     414        if ( !kernel_abort_called ) {                   // not first task to abort ?
     415                kernel_abort_called = true;
     416                unlock( &kernel_abort_lock );
     417        }
     418        else {
     419                unlock( &kernel_abort_lock );
     420               
     421                sigset_t mask;
     422                sigemptyset( &mask );
     423                sigaddset( &mask, SIGALRM );                    // block SIGALRM signals
     424                sigaddset( &mask, SIGUSR1 );                    // block SIGUSR1 signals
     425                sigsuspend( &mask );                            // block the processor to prevent further damage during abort
     426                _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it             
     427        }
     428
     429        return this_thread();
     430}
     431
     432void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) {
     433        thread_desc * thrd = kernel_data;
     434
     435        int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->cor.name, thrd );
     436        __lib_debug_write( STDERR_FILENO, abort_text, len );
     437
     438        if ( thrd != this_coroutine() ) {
     439                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() );
     440                __lib_debug_write( STDERR_FILENO, abort_text, len );
     441        }
     442        else {
     443                __lib_debug_write( STDERR_FILENO, ".\n", 2 );
     444        }
     445}
     446
     447extern "C" {
     448        void __lib_debug_acquire() {
     449                lock(&kernel_debug_lock);
     450        }
     451
     452        void __lib_debug_release() {
     453                unlock(&kernel_debug_lock);
     454        }
    397455}
    398456
  • src/libcfa/concurrency/thread.c

    r72dc82a r78d3dd5  
    7171        this_processor->current_coroutine = thrd_c;
    7272
    73         LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
     73        LIB_DEBUG_PRINT_SAFE("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
    7474
    7575        create_stack(&thrd_c->stack, thrd_c->stack.size);
Note: See TracChangeset for help on using the changeset viewer.