Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/preemption.cfa

    r09d4b22 r2026bb6  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  5 16:34:05 2019
    13 // Update Count     : 43
     12// Last Modified On : Tue Jun  5 17:35:49 2018
     13// Update Count     : 37
    1414//
    1515
     
    2424#include <string.h>
    2525#include <unistd.h>
    26 #include <limits.h>                                                                             // PTHREAD_STACK_MIN
    2726}
    2827
     
    6564event_kernel_t * event_kernel;                        // kernel public handle to even kernel
    6665static pthread_t alarm_thread;                        // pthread handle to alarm thread
    67 static void * alarm_stack;                                                        // pthread stack for alarm thread
    6866
    6967static void ?{}(event_kernel_t & this) with( this ) {
     
    8381// Get next expired node
    8482static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) {
    85         if( !alarms->head ) return 0p;                                          // If no alarms return null
    86         if( alarms->head->alarm >= currtime ) return 0p;        // If alarms head not expired return null
    87         return pop(alarms);                                                                     // Otherwise just pop head
     83        if( !alarms->head ) return NULL;                          // If no alarms return null
     84        if( alarms->head->alarm >= currtime ) return NULL;        // If alarms head not expired return null
     85        return pop(alarms);                                       // Otherwise just pop head
    8886}
    8987
    9088// Tick one frame of the Discrete Event Simulation for alarms
    9189static void tick_preemption() {
    92         alarm_node_t * node = 0p;                                                       // Used in the while loop but cannot be declared in the while condition
    93         alarm_list_t * alarms = &event_kernel->alarms;          // Local copy for ease of reading
    94         Time currtime = __kernel_get_time();                            // Check current time once so everything "happens at once"
     90        alarm_node_t * node = NULL;                     // Used in the while loop but cannot be declared in the while condition
     91        alarm_list_t * alarms = &event_kernel->alarms;  // Local copy for ease of reading
     92        Time currtime = __kernel_get_time();                    // Check current time once so we everything "happens at once"
    9593
    9694        //Loop throught every thing expired
     
    245243        sigaddset( &mask, sig );
    246244
    247         if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
     245        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    248246            abort( "internal error, pthread_sigmask" );
    249247        }
     
    256254        sigaddset( &mask, sig );
    257255
    258         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     256        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    259257            abort( "internal error, pthread_sigmask" );
    260258        }
     
    303301
    304302        // Setup proper signal handlers
    305         __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler
     303        __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART );         // CtxSwitch handler
    306304
    307305        signal_block( SIGALRM );
    308306
    309         alarm_stack = create_pthread( &alarm_thread, alarm_loop, 0p );
     307        pthread_create( &alarm_thread, NULL, alarm_loop, NULL );
    310308}
    311309
     
    318316        sigset_t mask;
    319317        sigfillset( &mask );
    320         sigprocmask( SIG_BLOCK, &mask, 0p );
     318        sigprocmask( SIG_BLOCK, &mask, NULL );
    321319
    322320        // Notify the alarm thread of the shutdown
     
    325323
    326324        // Wait for the preemption thread to finish
    327 
    328         pthread_join( alarm_thread, 0p );
    329         free( alarm_stack );
     325        pthread_join( alarm_thread, NULL );
    330326
    331327        // Preemption is now fully stopped
     
    384380        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    385381        #endif
    386         if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
     382        if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) {
    387383                abort( "internal error, sigprocmask" );
    388384        }
     
    403399        sigset_t mask;
    404400        sigfillset(&mask);
    405         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     401        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    406402            abort( "internal error, pthread_sigmask" );
    407403        }
     
    424420                                        {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );}
    425421                                        continue;
    426                                 case EINVAL :
     422                        case EINVAL :
    427423                                        abort( "Timeout was invalid." );
    428424                                default:
     
    457453EXIT:
    458454        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    459         return 0p;
     455        return NULL;
    460456}
    461457
     
    470466        sigset_t oldset;
    471467        int ret;
    472         ret = pthread_sigmask(0, 0p, &oldset);
     468        ret = pthread_sigmask(0, NULL, &oldset);
    473469        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    474470
Note: See TracChangeset for help on using the changeset viewer.