Ignore:
File:
1 edited

Legend:

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

    r9d944b2 r17af7d1  
    1515//
    1616
    17 #include "startup.h"
    18 
    1917//Start and stop routine for the kernel, declared first to make sure they run first
    20 void kernel_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) ));
    21 void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL ) ));
     18void kernel_startup(void)  __attribute__((constructor(101)));
     19void kernel_shutdown(void) __attribute__((destructor(101)));
    2220
    2321//Header
     
    2725#include <stddef.h>
    2826extern "C" {
    29 #include <stdio.h>
    3027#include <fenv.h>
    3128#include <sys/resource.h>
    32 #include <signal.h>
    33 #include <unistd.h>
    3429}
    3530
     
    151146
    152147        this->runner = runner;
    153         LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner);
     148        LIB_DEBUG_PRINTF("Kernel : constructing processor context %p\n", runner);
    154149        runner{ this };
    155150}
     
    157152void ^?{}(processor * this) {
    158153        if( ! this->is_terminated ) {
    159                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this);
     154                LIB_DEBUG_PRINTF("Kernel : core %p signaling termination\n", this);
    160155                this->is_terminated = true;
    161156                wait( &this->terminated );
     
    178173void main(processorCtx_t * runner) {
    179174        processor * this = runner->proc;
    180         LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     175        LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this);
    181176
    182177        thread_desc * readyThread = NULL;
     
    200195        }
    201196
    202         LIB_DEBUG_PRINT_SAFE("Kernel : core %p unlocking thread\n", this);
     197        LIB_DEBUG_PRINTF("Kernel : core %p unlocking thread\n", this);
    203198        signal( &this->terminated );
    204         LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this);
     199        LIB_DEBUG_PRINTF("Kernel : core %p terminated\n", this);
    205200}
    206201
     
    260255        processorCtx_t proc_cor_storage = { proc, &info };
    261256
    262         LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
     257        LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    263258
    264259        //Set global state
     
    267262
    268263        //We now have a proper context from which to schedule threads
    269         LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
     264        LIB_DEBUG_PRINTF("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    270265
    271266        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     
    278273
    279274        // Main routine of the core returned, the core is now fully terminated
    280         LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
     275        LIB_DEBUG_PRINTF("Kernel : core %p main ended (%p)\n", proc, proc->runner);     
    281276
    282277        return NULL;
     
    284279
    285280void start(processor * this) {
    286         LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
     281        LIB_DEBUG_PRINTF("Kernel : Starting core %p\n", this);
    287282       
    288283        // pthread_attr_t attributes;
     
    293288        // pthread_attr_destroy( &attributes );
    294289
    295         LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);       
     290        LIB_DEBUG_PRINTF("Kernel : core %p started\n", this);   
    296291}
    297292
     
    339334// Kernel boot procedures
    340335void kernel_startup(void) {
    341         LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");   
     336        LIB_DEBUG_PRINTF("Kernel : Starting\n");       
    342337
    343338        // Start by initializing the main thread
     
    374369
    375370        // THE SYSTEM IS NOW COMPLETELY RUNNING
    376         LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");
     371        LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n");
    377372}
    378373
    379374void kernel_shutdown(void) {
    380         LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");
     375        LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down\n");
    381376
    382377        // SKULLDUGGERY: Notify the systemProcessor it needs to terminates.
     
    397392        ^(mainThread){};
    398393
    399         LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");   
    400 }
    401 
    402 static spinlock kernel_abort_lock;
    403 static spinlock kernel_debug_lock;
    404 static bool kernel_abort_called = false;
    405 
    406 void * kernel_abort    (void) __attribute__ ((__nothrow__)) {
    407         // abort cannot be recursively entered by the same or different processors because all signal handlers return when
    408         // the globalAbort flag is true.
    409         lock( &kernel_abort_lock );
    410 
    411         // first task to abort ?
    412         if ( !kernel_abort_called ) {                   // not first task to abort ?
    413                 kernel_abort_called = true;
    414                 unlock( &kernel_abort_lock );
    415         }
    416         else {
    417                 unlock( &kernel_abort_lock );
    418                
    419                 sigset_t mask;
    420                 sigemptyset( &mask );
    421                 sigaddset( &mask, SIGALRM );                    // block SIGALRM signals
    422                 sigaddset( &mask, SIGUSR1 );                    // block SIGUSR1 signals
    423                 sigsuspend( &mask );                            // block the processor to prevent further damage during abort
    424                 _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it             
    425         }
    426 
    427         return this_thread();
    428 }
    429 
    430 void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) {
    431         thread_desc * thrd = kernel_data;
    432 
    433         int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->cor.name, thrd );
    434         __lib_debug_write( STDERR_FILENO, abort_text, len );
    435 
    436         if ( thrd != this_coroutine() ) {
    437                 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() );
    438                 __lib_debug_write( STDERR_FILENO, abort_text, len );
    439         }
    440         else {
    441                 __lib_debug_write( STDERR_FILENO, ".\n", 2 );
    442         }
    443 }
    444 
    445 extern "C" {
    446         void __lib_debug_acquire() {
    447                 lock(&kernel_debug_lock);
    448         }
    449 
    450         void __lib_debug_release() {
    451                 unlock(&kernel_debug_lock);
    452         }
     394        LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n");       
    453395}
    454396
Note: See TracChangeset for help on using the changeset viewer.