Ignore:
Timestamp:
Dec 10, 2019, 4:24:49 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2a3d446
Parents:
b798713 (diff), e307e12 (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' into relaxed_ready

File:
1 edited

Legend:

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

    rb798713 rf80f840  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  5 17:35:49 2018
    13 // Update Count     : 37
     12// Last Modified On : Thu Dec  5 16:34:05 2019
     13// Update Count     : 43
    1414//
    1515
     
    2424#include <string.h>
    2525#include <unistd.h>
     26#include <limits.h>                                                                             // PTHREAD_STACK_MIN
    2627}
    2728
     
    6465event_kernel_t * event_kernel;                        // kernel public handle to even kernel
    6566static pthread_t alarm_thread;                        // pthread handle to alarm thread
     67static void * alarm_stack;                                                        // pthread stack for alarm thread
    6668
    6769static void ?{}(event_kernel_t & this) with( this ) {
     
    8183// Get next expired node
    8284static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) {
    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
     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
    8688}
    8789
    8890// Tick one frame of the Discrete Event Simulation for alarms
    8991static void tick_preemption() {
    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"
     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"
    9395
    9496        //Loop throught every thing expired
     
    243245        sigaddset( &mask, sig );
    244246
    245         if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
     247        if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
    246248            abort( "internal error, pthread_sigmask" );
    247249        }
     
    254256        sigaddset( &mask, sig );
    255257
    256         if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     258        if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    257259            abort( "internal error, pthread_sigmask" );
    258260        }
     
    301303
    302304        // Setup proper signal handlers
    303         __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART );         // CtxSwitch handler
     305        __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler
    304306
    305307        signal_block( SIGALRM );
    306308
    307         pthread_create( &alarm_thread, NULL, alarm_loop, NULL );
     309        alarm_stack = create_pthread( &alarm_thread, alarm_loop, 0p );
    308310}
    309311
     
    316318        sigset_t mask;
    317319        sigfillset( &mask );
    318         sigprocmask( SIG_BLOCK, &mask, NULL );
     320        sigprocmask( SIG_BLOCK, &mask, 0p );
    319321
    320322        // Notify the alarm thread of the shutdown
     
    323325
    324326        // Wait for the preemption thread to finish
    325         pthread_join( alarm_thread, NULL );
     327
     328        pthread_join( alarm_thread, 0p );
     329        free( alarm_stack );
    326330
    327331        // Preemption is now fully stopped
     
    380384        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    381385        #endif
    382         if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) {
     386        if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
    383387                abort( "internal error, sigprocmask" );
    384388        }
     
    399403        sigset_t mask;
    400404        sigfillset(&mask);
    401         if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     405        if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    402406            abort( "internal error, pthread_sigmask" );
    403407        }
     
    420424                                        {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );}
    421425                                        continue;
    422                         case EINVAL :
     426                                case EINVAL :
    423427                                        abort( "Timeout was invalid." );
    424428                                default:
     
    453457EXIT:
    454458        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    455         return NULL;
     459        return 0p;
    456460}
    457461
     
    466470        sigset_t oldset;
    467471        int ret;
    468         ret = pthread_sigmask(0, NULL, &oldset);
     472        ret = pthread_sigmask(0, 0p, &oldset);
    469473        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    470474
Note: See TracChangeset for help on using the changeset viewer.