Changeset 27f5f71


Ignore:
Timestamp:
Nov 30, 2019, 11:08:34 AM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4cae032
Parents:
524627e
Message:

explicitly create stack for pthread thread, change NULL to 0p

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.h

    r524627e r27f5f71  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 22 18:19:13 2019
    13 // Update Count     : 40
     12// Last Modified On : Thu Nov 28 22:34:07 2019
     13// Update Count     : 41
    1414//
    1515
     
    5151
    5252                        struct {
     53                                void * stack;
    5354                                volatile unsigned short disable_count;
    5455                                volatile bool enabled;
  • libcfa/src/concurrency/kernel.cfa

    r524627e r27f5f71  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 21 16:46:59 2019
    13 // Update Count     : 27
     12// Last Modified On : Fri Nov 29 17:59:16 2019
     13// Update Count     : 35
    1414//
    1515
     
    2626#include <signal.h>
    2727#include <unistd.h>
     28#include <limits.h>                                                                             // PTHREAD_STACK_MIN
    2829}
    2930
     
    133134        NULL,
    134135        NULL,
    135         { 1, false, false },
     136        { NULL, 1, false, false },
    136137        6u //this should be seeded better but due to a bug calling rdtsc doesn't work
    137138};
     
    233234
    234235        pthread_join( kernel_thread, NULL );
     236        free( this.stack );
    235237}
    236238
     
    445447        __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);
    446448
    447         pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
     449        pthread_attr_t attr;
     450        int ret;
     451        ret = pthread_attr_init( &attr );                                       // initialize attribute
     452        if ( ret ) {
     453                abort( "%s : internal error, pthread_attr_init failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     454        } // if
     455
     456        size_t stacksize;
     457        ret = pthread_attr_getstacksize( &attr, &stacksize ); // default stack size, normally defined by shell limit
     458        if ( ret ) {
     459                abort( "%s : internal error, pthread_attr_getstacksize failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     460        } // if
     461        assert( stacksize >= PTHREAD_STACK_MIN );
     462
     463        this->stack = malloc( stacksize );
     464        ret = pthread_attr_setstack( &attr, this->stack, stacksize );
     465        if ( ret ) {
     466                abort( "%s : internal error, pthread_attr_setstack failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     467        } // if
     468
     469        ret = pthread_create( &this->kernel_thread, &attr, CtxInvokeProcessor, (void *)this );
     470        if ( ret ) {
     471                abort( "%s : internal error, pthread_create failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     472        } // if
     473//      pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    448474
    449475        __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
  • libcfa/src/concurrency/kernel.hfa

    r524627e r27f5f71  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 22 11:39:17 2019
    13 // Update Count     : 16
     12// Last Modified On : Thu Nov 28 21:24:12 2019
     13// Update Count     : 17
    1414//
    1515
     
    135135        semaphore terminated;
    136136
     137        // pthread Stack
     138        void * stack;
     139
    137140        // Link lists fields
    138141        struct __dbg_node_proc {
  • libcfa/src/concurrency/preemption.cfa

    r524627e r27f5f71  
    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 : Sat Nov 30 08:02:56 2019
     13// Update Count     : 39
    1414//
    1515
     
    2424#include <string.h>
    2525#include <unistd.h>
     26#include <limits.h>                                                                             // PTHREAD_STACK_MIN
    2627}
    2728
     
    8182// Get next expired node
    8283static 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
     84        if( !alarms->head ) return 0p;                                          // If no alarms return null
     85        if( alarms->head->alarm >= currtime ) return 0p;        // If alarms head not expired return null
     86        return pop(alarms);                                                                     // Otherwise just pop head
    8687}
    8788
    8889// Tick one frame of the Discrete Event Simulation for alarms
    8990static 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"
     91        alarm_node_t * node = 0p;                                                       // Used in the while loop but cannot be declared in the while condition
     92        alarm_list_t * alarms = &event_kernel->alarms;          // Local copy for ease of reading
     93        Time currtime = __kernel_get_time();                            // Check current time once so everything "happens at once"
    9394
    9495        //Loop throught every thing expired
     
    243244        sigaddset( &mask, sig );
    244245
    245         if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
     246        if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
    246247            abort( "internal error, pthread_sigmask" );
    247248        }
     
    254255        sigaddset( &mask, sig );
    255256
    256         if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     257        if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    257258            abort( "internal error, pthread_sigmask" );
    258259        }
     
    301302
    302303        // Setup proper signal handlers
    303         __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART );         // CtxSwitch handler
     304        __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler
    304305
    305306        signal_block( SIGALRM );
    306307
    307         pthread_create( &alarm_thread, NULL, alarm_loop, NULL );
     308        pthread_attr_t attr;
     309        int ret;
     310        ret = pthread_attr_init( &attr );                                       // initialize attribute
     311        if ( ret ) {
     312                abort( "%s : internal error, pthread_attr_init failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     313        } // if
     314
     315        size_t stacksize;
     316        ret = pthread_attr_getstacksize( &attr, &stacksize ); // default stack size, normally defined by shell limit
     317        if ( ret ) {
     318                abort( "%s : internal error, pthread_attr_getstacksize failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     319        } // if
     320        assert( stacksize >= PTHREAD_STACK_MIN );
     321
     322        kernelTLS.preemption_state.stack = malloc( stacksize );
     323        ret = pthread_attr_setstack( &attr, kernelTLS.preemption_state.stack, stacksize );
     324        if ( ret ) {
     325                abort( "%s : internal error, pthread_attr_setstack failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     326        } // if
     327
     328        ret = pthread_create( &alarm_thread, &attr, alarm_loop, 0p );
     329        if ( ret ) {
     330                abort( "%s : internal error, pthread_create failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     331        } // if
    308332}
    309333
     
    316340        sigset_t mask;
    317341        sigfillset( &mask );
    318         sigprocmask( SIG_BLOCK, &mask, NULL );
     342        sigprocmask( SIG_BLOCK, &mask, 0p );
    319343
    320344        // Notify the alarm thread of the shutdown
     
    323347
    324348        // Wait for the preemption thread to finish
    325         pthread_join( alarm_thread, NULL );
     349
     350        pthread_join( alarm_thread, 0p );
     351        free( kernelTLS.preemption_state.stack );
    326352
    327353        // Preemption is now fully stopped
     
    380406        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    381407        #endif
    382         if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) {
     408        if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
    383409                abort( "internal error, sigprocmask" );
    384410        }
     
    399425        sigset_t mask;
    400426        sigfillset(&mask);
    401         if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     427        if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    402428            abort( "internal error, pthread_sigmask" );
    403429        }
     
    420446                                        {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );}
    421447                                        continue;
    422                         case EINVAL :
     448                                case EINVAL :
    423449                                        abort( "Timeout was invalid." );
    424450                                default:
     
    453479EXIT:
    454480        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    455         return NULL;
     481        return 0p;
    456482}
    457483
     
    466492        sigset_t oldset;
    467493        int ret;
    468         ret = pthread_sigmask(0, NULL, &oldset);
     494        ret = pthread_sigmask(0, 0p, &oldset);
    469495        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    470496
Note: See TracChangeset for help on using the changeset viewer.