Changes in / [ce7bdc4:78cdb06]


Ignore:
Files:
13 edited

Legend:

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

    rce7bdc4 r78cdb06  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Nov 30 09:59:36 2019
    13 // Update Count     : 14
     12// Last Modified On : Fri Mar 30 17:20:57 2018
     13// Update Count     : 9
    1414//
    1515
     
    9090
    9191void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize ) with( this ) {
    92         (this.context){0p, 0p};
     92        (this.context){NULL, NULL};
    9393        (this.stack){storage, storageSize};
    9494        this.name = name;
    9595        state = Start;
    96         starter = 0p;
    97         last = 0p;
    98         cancellation = 0p;
     96        starter = NULL;
     97        last = NULL;
     98        cancellation = NULL;
    9999}
    100100
  • libcfa/src/concurrency/invoke.h

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

    rce7bdc4 r78cdb06  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 17:59:16 2019
    13 // Update Count     : 35
     12// Last Modified On : Thu Nov 21 16:46:59 2019
     13// Update Count     : 27
    1414//
    1515
     
    2626#include <signal.h>
    2727#include <unistd.h>
    28 #include <limits.h>                                                                             // PTHREAD_STACK_MIN
    2928}
    3029
     
    134133        NULL,
    135134        NULL,
    136         { NULL, 1, false, false },
     135        { 1, false, false },
    137136        6u //this should be seeded better but due to a bug calling rdtsc doesn't work
    138137};
     
    234233
    235234        pthread_join( kernel_thread, NULL );
    236         free( this.stack );
    237235}
    238236
     
    447445        __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);
    448446
    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 );
     447        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    474448
    475449        __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
  • libcfa/src/concurrency/kernel.hfa

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

    rce7bdc4 r78cdb06  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Nov 30 08:02:56 2019
    13 // Update Count     : 39
     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
     
    8281// Get next expired node
    8382static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) {
    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
     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
    8786}
    8887
    8988// Tick one frame of the Discrete Event Simulation for alarms
    9089static void tick_preemption() {
    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"
     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"
    9493
    9594        //Loop throught every thing expired
     
    244243        sigaddset( &mask, sig );
    245244
    246         if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
     245        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    247246            abort( "internal error, pthread_sigmask" );
    248247        }
     
    255254        sigaddset( &mask, sig );
    256255
    257         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     256        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    258257            abort( "internal error, pthread_sigmask" );
    259258        }
     
    302301
    303302        // Setup proper signal handlers
    304         __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler
     303        __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART );         // CtxSwitch handler
    305304
    306305        signal_block( SIGALRM );
    307306
    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
     307        pthread_create( &alarm_thread, NULL, alarm_loop, NULL );
    332308}
    333309
     
    340316        sigset_t mask;
    341317        sigfillset( &mask );
    342         sigprocmask( SIG_BLOCK, &mask, 0p );
     318        sigprocmask( SIG_BLOCK, &mask, NULL );
    343319
    344320        // Notify the alarm thread of the shutdown
     
    347323
    348324        // Wait for the preemption thread to finish
    349 
    350         pthread_join( alarm_thread, 0p );
    351         free( kernelTLS.preemption_state.stack );
     325        pthread_join( alarm_thread, NULL );
    352326
    353327        // Preemption is now fully stopped
     
    406380        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    407381        #endif
    408         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 ) {
    409383                abort( "internal error, sigprocmask" );
    410384        }
     
    425399        sigset_t mask;
    426400        sigfillset(&mask);
    427         if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     401        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    428402            abort( "internal error, pthread_sigmask" );
    429403        }
     
    446420                                        {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );}
    447421                                        continue;
    448                                 case EINVAL :
     422                        case EINVAL :
    449423                                        abort( "Timeout was invalid." );
    450424                                default:
     
    479453EXIT:
    480454        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    481         return 0p;
     455        return NULL;
    482456}
    483457
     
    492466        sigset_t oldset;
    493467        int ret;
    494         ret = pthread_sigmask(0, 0p, &oldset);
     468        ret = pthread_sigmask(0, NULL, &oldset);
    495469        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    496470
  • libcfa/src/fstream.cfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 06:56:46 2019
    13 // Update Count     : 355
     12// Last Modified On : Tue Sep 10 22:19:56 2019
     13// Update Count     : 354
    1414//
    1515
     
    6666} // ?{}
    6767
    68 void ^?{}( ofstream & os ) {
    69         close( os );
    70 } // ^?{}
    71 
    7268void sepOn( ofstream & os ) { os.sepOnOff = ! getNL( os ); }
    7369void sepOff( ofstream & os ) { os.sepOnOff = false; }
     
    199195} // ?{}
    200196
    201 void ^?{}( ifstream & is ) {
    202         close( is );
    203 } // ^?{}
    204 
    205197void nlOn( ifstream & os ) { os.nlOnOff = true; }
    206198void nlOff( ifstream & os ) { os.nlOnOff = false; }
  • libcfa/src/fstream.hfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 06:56:02 2019
    13 // Update Count     : 168
     12// Last Modified On : Mon Jul 15 18:10:23 2019
     13// Update Count     : 167
    1414//
    1515
     
    7272void ?{}( ofstream & os, const char * name, const char * mode );
    7373void ?{}( ofstream & os, const char * name );
    74 void ^?{}( ofstream & os );
    7574
    7675extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
     
    102101void ?{}( ifstream & is, const char * name, const char * mode );
    103102void ?{}( ifstream & is, const char * name );
    104 void ^?{}( ifstream & is );
    105103
    106104extern ifstream & sin, & stdin;                                                 // aliases
  • libcfa/src/heap.cfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 17:33:58 2019
    13 // Update Count     : 641
     12// Last Modified On : Sun Nov 24 17:56:15 2019
     13// Update Count     : 638
    1414//
    1515
     
    7171
    7272
     73// static bool traceHeapTerm = false;
     74
     75// inline bool traceHeapTerm() {
     76//      return traceHeapTerm;
     77// } // traceHeapTerm
     78
     79// bool traceHeapTermOn() {
     80//      bool temp = traceHeapTerm;
     81//      traceHeapTerm = true;
     82//      return temp;
     83// } // traceHeapTermOn
     84
     85// bool traceHeapTermOff() {
     86//      bool temp = traceHeapTerm;
     87//      traceHeapTerm = false;
     88//      return temp;
     89// } // traceHeapTermOff
     90
     91
    7392enum {
    7493        // Define the default extension heap amount in units of bytes. When the uC++ supplied heap reaches the brk address,
     
    96115        if ( allocFree != 0 ) {
    97116                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    98                 char helpText[512];
    99                 int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
    100                                                         "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
    101                                                         (long int)getpid(), allocFree, allocFree ); // always print the UNIX pid
    102                 __cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug
     117                // char helpText[512];
     118                // int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
     119                //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
     120                //                                      (long int)getpid(), allocFree, allocFree ); // always print the UNIX pid
     121                // __cfaabi_dbg_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug
    103122        } // if
    104123} // prtUnfreed
  • libcfa/src/interpose.cfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Nov 30 07:09:42 2019
    13 // Update Count     : 119
     12// Last Modified On : Thu Nov 21 16:47:02 2019
     13// Update Count     : 118
    1414//
    1515
     
    196196        __cfaabi_bits_print_nolock( STDERR_FILENO, "Stack back trace for: %s\n", messages[0]);
    197197
    198         for ( int i = Start; i < size - abort_lastframe && messages != 0p; i += 1 ) {
    199                 char * name = 0p, * offset_begin = 0p, * offset_end = 0p;
     198        for ( int i = Start; i < size - abort_lastframe && messages != NULL; i += 1 ) {
     199                char * name = NULL, * offset_begin = NULL, * offset_end = NULL;
    200200
    201201                for ( char * p = messages[i]; *p; ++p ) {
  • libcfa/src/startup.cfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Tue Jul 24 16:21:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Nov 30 07:07:56 2019
    13 // Update Count     : 13
     12// Last Modified On : Wed Jul 25 16:42:01 2018
     13// Update Count     : 11
    1414//
    1515
    1616#include "startup.hfa"
    17 #include <time.h>                                                                               // tzset
     17#include <unistd.h>
     18
    1819
    1920extern "C" {
    2021    static void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) ));
    2122    void __cfaabi_appready_startup( void ) {
    22                 tzset();                                                                                // initialize time global variables
    2323                #ifdef __CFA_DEBUG__
    2424                extern void heapAppStart();
  • libcfa/src/stdlib.hfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 23:08:02 2019
    13 // Update Count     : 400
     12// Last Modified On : Fri Nov 22 15:13:14 2019
     13// Update Count     : 399
    1414//
    1515
     
    210210
    211211static inline {
    212         int ato( const char * sptr ) { return (int)strtol( sptr, 0p, 10 ); }
    213         unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0p, 10 ); }
    214         long int ato( const char * sptr ) { return strtol( sptr, 0p, 10 ); }
    215         unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0p, 10 ); }
    216         long long int ato( const char * sptr ) { return strtoll( sptr, 0p, 10 ); }
    217         unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0p, 10 ); }
    218 
    219         float ato( const char * sptr ) { return strtof( sptr, 0p ); }
    220         double ato( const char * sptr ) { return strtod( sptr, 0p ); }
    221         long double ato( const char * sptr ) { return strtold( sptr, 0p ); }
    222 
    223         float _Complex ato( const char * sptr ) { return strto( sptr, 0p ); }
    224         double _Complex ato( const char * sptr ) { return strto( sptr, 0p ); }
    225         long double _Complex ato( const char * sptr ) { return strto( sptr, 0p ); }
     212        int ato( const char * sptr ) { return (int)strtol( sptr, 0, 10 ); }
     213        unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
     214        long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
     215        unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
     216        long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
     217        unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
     218
     219        float ato( const char * sptr ) { return strtof( sptr, 0 ); }
     220        double ato( const char * sptr ) { return strtod( sptr, 0 ); }
     221        long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
     222
     223        float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     224        double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     225        long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    226226} // distribution
    227227
  • tests/concurrent/thread.cfa

    rce7bdc4 r78cdb06  
    77thread Second { semaphore* lock; };
    88
    9 void ?{}( First  & this, semaphore & lock ) { ((thread&)this).self_cor.name = "Thread 1"; this.lock = &lock; }
    10 void ?{}( Second & this, semaphore & lock ) { ((thread&)this).self_cor.name = "Thread 2"; this.lock = &lock; }
     9void ?{}( First  & this, semaphore & lock ) { ((thread&)this){"Thread 1"}; this.lock = &lock; }
     10void ?{}( Second & this, semaphore & lock ) { ((thread&)this){"Thread 2"}; this.lock = &lock; }
    1111
    1212void main(First& this) {
  • tests/time.cfa

    rce7bdc4 r78cdb06  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 29 23:05:30 2019
    13 // Update Count     : 24
     12// Last Modified On : Thu Dec 20 23:09:21 2018
     13// Update Count     : 23
    1414//
    1515
     
    2020        Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns;
    2121        sout | d1 | d2 | d3 | d4 | d5;
     22        int i;
    2223        d1 = 0;
    2324        sout | d1 | d2 | d3;
Note: See TracChangeset for help on using the changeset viewer.