Changes in / [956b389:3e2e9b2]


Ignore:
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    r956b389 r3e2e9b2  
    4444typedef unsigned long long __cfaabi_abi_exception_type_t;
    4545
    46 #include <limits.h>                                                                             // CHAR_BIT
    4746#include "../src/virtual.h"
    4847#include "../src/exception.h"
     
    132131} // distribution
    133132
    134 #define __CFA_EXP__() \
    135         if ( y == 0 ) return 1;                                                         /* convention */ \
    136         __CFA_EXP_INT__(                                                                        /* special cases for integral types */ \
    137                 if ( x == 1 ) return 1;                                                 /* base case */ \
    138                 if ( x == 2 ) return x << (y - 1);                              /* positive shifting */ \
    139                 if ( y >= sizeof(y) * CHAR_BIT ) return 0;              /* immediate overflow, negative exponent > 2^size-1 */ \
    140         ) \
    141         typeof(x) op = 1;                                                                       /* accumulate odd product */ \
    142         typeof(x) w = x; /* FIX-ME: possible bug in the box pass changing value argument through parameter */ \
    143         for ( ; y > 1; y >>= 1 ) {                                                      /* squaring exponentiation, O(log2 y) */ \
    144                 if ( (y & 1) == 1 ) op = op * w;                                /* odd ? */ \
    145                 w = w * w; \
    146         } \
    147         return w * op
    148 #define __CFA_EXP_INT__(...) __VA_ARGS__
     133int ?\?( int x, unsigned int y );
     134long int ?\?( long int x, unsigned long int y );
     135long long int ?\?( long long int x, unsigned long long int y );
     136// unsigned computation may be faster and larger
     137unsigned int ?\?( unsigned int x, unsigned int y );
     138unsigned long int ?\?( unsigned long int x, unsigned long int y );
     139unsigned long long int ?\?( unsigned long long int x, unsigned long long int y );
    149140
    150 static inline {
    151         int ?\?( int x, unsigned int y ) { __CFA_EXP__(); }
    152         long int ?\?( long int x, unsigned long int y ) { __CFA_EXP__(); }
    153         long long int ?\?( long long int x, unsigned long long int y ) { __CFA_EXP__(); }
    154         // unsigned computation may be faster and larger
    155         unsigned int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); }
    156         unsigned long int ?\?( unsigned long int x, unsigned long int y ) { __CFA_EXP__(); }
    157         unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ) { __CFA_EXP__(); }
     141forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
     142        OT ?\?( OT x, unsigned int y );
     143        OT ?\?( OT x, unsigned long int y );
     144        OT ?\?( OT x, unsigned long long int y );
    158145} // distribution
    159 
    160 #undef __CFA_EXP_INT__
    161 #define __CFA_EXP_INT__(...)
    162 
    163 static inline forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
    164         OT ?\?( OT x, unsigned int y ) { __CFA_EXP__(); }
    165         OT ?\?( OT x, unsigned long int y ) { __CFA_EXP__(); }
    166         OT ?\?( OT x, unsigned long long int y ) { __CFA_EXP__(); }
    167 } // distribution
    168 
    169 #undef __CFA_EXP_INT__
    170 #undef __CFA_EXP__
    171146
    172147static inline {
  • libcfa/src/Makefile.am

    r956b389 r3e2e9b2  
    4747        gmp.hfa \
    4848        math.trait.hfa \
    49         math.hfa \
    5049        raii.hfa \
    5150        time_t.hfa \
     
    8180        iterator.hfa \
    8281        limits.hfa \
     82        math.hfa \
    8383        memory.hfa \
    8484        parseargs.hfa \
  • libcfa/src/concurrency/monitor.cfa

    r956b389 r3e2e9b2  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 21 08:31:55 2024
    13 // Update Count     : 18
     12// Last Modified On : Wed Nov 27 12:13:14 2024
     13// Update Count     : 72
    1414//
    1515
     
    2727//-----------------------------------------------------------------------------
    2828// Forward declarations
    29 static inline void __set_owner ( monitor$ * this, thread$ * owner );
    30 static inline void __set_owner ( monitor$ * storage [], __lock_size_t count, thread$ * owner );
    31 static inline void set_mask  ( monitor$ * storage [], __lock_size_t count, const __waitfor_mask_t & mask );
     29static inline void __set_owner( monitor$ * this, thread$ * owner );
     30static inline void __set_owner( monitor$ * storage [], __lock_size_t count, thread$ * owner );
     31static inline void set_mask( monitor$ * storage [], __lock_size_t count, const __waitfor_mask_t & mask );
    3232static inline void reset_mask( monitor$ * this );
    3333
     
    3535static inline bool is_accepted( monitor$ * this, const __monitor_group_t & monitors );
    3636
    37 static inline void lock_all  ( __spinlock_t * locks [], __lock_size_t count );
    38 static inline void lock_all  ( monitor$ * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count );
     37static inline void lock_all( __spinlock_t * locks [], __lock_size_t count );
     38static inline void lock_all( monitor$ * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count );
    3939static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count );
    4040static inline void unlock_all( monitor$ * locks [], __lock_size_t count );
    4141
    42 static inline void save   ( monitor$ * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
     42static inline void save( monitor$ * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
    4343static inline void restore( monitor$ * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
    4444
     
    4747static inline void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t * owner );
    4848
    49 static inline void init     ( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     49static inline void init( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    5050static inline void init_push( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    5151
    52 static inline thread$ *        check_condition  ( __condition_criterion_t * );
    53 static inline void                 brand_condition   ( condition & );
     52static inline thread$ * check_condition ( __condition_criterion_t * );
     53static inline void brand_condition( condition & );
    5454static inline [thread$ *, int] search_entry_queue( const __waitfor_mask_t &, monitor$ * monitors [], __lock_size_t count );
    5555
    5656forall(T & | sized( T ))
    5757static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val );
    58 static inline __lock_size_t count_max    ( const __waitfor_mask_t & mask );
    59 static inline __lock_size_t aggregate    ( monitor$ * storage [], const __waitfor_mask_t & mask );
     58static inline __lock_size_t count_max( const __waitfor_mask_t & mask );
     59static inline __lock_size_t aggregate( monitor$ * storage [], const __waitfor_mask_t & mask );
    6060
    6161//-----------------------------------------------------------------------------
    6262// Useful defines
    63 #define wait_ctx(thrd, user_info)                               /* Create the necessary information to use the signaller stack                        */ \
    64         __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                    */ \
    65         __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
    66         init( count, monitors, waiter, criteria );                /* Link everything together                                                            */ \
    67 
    68 #define wait_ctx_primed(thrd, user_info)                        /* Create the necessary information to use the signaller stack                        */ \
    69         __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                    */ \
    70         __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
    71         init_push( count, monitors, waiter, criteria );           /* Link everything together and push it to the AS-Stack                                */ \
    72 
    73 #define monitor_ctx( mons, cnt )                                /* Define that create the necessary struct for internal/external scheduling operations */ \
    74         monitor$ ** monitors = mons;                          /* Save the targeted monitors                                                          */ \
    75         __lock_size_t count = cnt;                                /* Save the count to a local variable                                                  */ \
    76         unsigned int recursions[ count ];                         /* Save the current recursion levels to restore them later                            */ \
    77         __waitfor_mask_t masks [ count ];                         /* Save the current waitfor masks to restore them later                                */ \
    78         __spinlock_t *   locks [ count ];                         /* We need to pass-in an array of locks to BlockInternal                               */ \
     63#define wait_ctx( thrd, user_info )                                                     /* Create the necessary information to use the signaller stack */ \
     64        __condition_node_t waiter = { thrd, count, user_info }; /* Create the node specific to this wait operation */ \
     65        __condition_criterion_t criteria[count];                                /* Create the creteria this wait operation needs to wake up */ \
     66        init( count, monitors, waiter, criteria );                              /* Link everything together */
     67
     68#define wait_ctx_primed( thrd, user_info )                                      /* Create the necessary information to use the signaller stack */ \
     69        __condition_node_t waiter = { thrd, count, user_info }; /* Create the node specific to this wait operation */ \
     70        __condition_criterion_t criteria[count];                                /* Create the creteria this wait operation needs to wake up */ \
     71        init_push( count, monitors, waiter, criteria );                 /* Link everything together and push it to the AS-Stack */
     72
     73#define monitor_ctx( mons, cnt )                                                        /* Define that create the necessary struct for internal/external scheduling operations */ \
     74        monitor$ ** monitors = mons;                                                    /* Save the targeted monitors */ \
     75        __lock_size_t count = cnt;                                                              /* Save the count to a local variable */ \
     76        unsigned int recursions[count];                                                 /* Save the current recursion levels to restore them later */ \
     77        __waitfor_mask_t masks[count];                                                  /* Save the current waitfor masks to restore them later */ \
     78        __spinlock_t * locks[count];                                                    /* We need to pass-in an array of locks to BlockInternal */
    7979
    8080#define monitor_save    save   ( monitors, count, locks, recursions, masks )
     
    9393        __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9494
    95         if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
     95        if ( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
    9696                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
    97         }
    98         else if( !this->owner ) {
     97        } else if ( !this->owner ) {
    9998                // No one has the monitor, just take it
    10099                __set_owner( this, thrd );
    101100
    102101                __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
    103         }
    104         else if( this->owner == thrd) {
     102        } else if ( this->owner == thrd) {
    105103                // We already have the monitor, just note how many times we took it
    106104                this->recursion += 1;
    107105
    108106                __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
    109         }
    110         else if( is_accepted( this, group) ) {
     107        } else if ( is_accepted( this, group) ) {
    111108                // Some one was waiting for us, enter
    112109                __set_owner( this, thrd );
     
    116113
    117114                __cfaabi_dbg_print_safe( "Kernel :  mon accepts \n" );
    118         }
    119         else {
     115        } else {
    120116                __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    121117
     
    156152
    157153
    158         if( !this->owner ) {
     154        if ( !this->owner ) {
    159155                __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
    160156
     
    167163                unlock( this->lock );
    168164                return;
    169         }
    170         else if( this->owner == thrd && !join) {
     165        } else if ( this->owner == thrd && !join) {
    171166                // We already have the monitor... but where about to destroy it so the nesting will fail
    172167                // Abort!
     
    176171        // because join will not release the monitor after it executed.
    177172        // to avoid that it sets the owner to the special value thrd | 1p before exiting
    178         else if( this->owner == (thread$*)(1 | (uintptr_t)thrd) ) {
     173        else if ( this->owner == (thread$*)(1 | (uintptr_t)thrd) ) {
    179174                // restore the owner and just return
    180175                __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
     
    196191        monitor$ ** monitors = &this;
    197192        __monitor_group_t group = { &this, 1, func };
    198         if( is_accepted( this, group) ) {
     193        if ( is_accepted( this, group) ) {
    199194                __cfaabi_dbg_print_safe( "Kernel :  mon accepts dtor, block and signal it \n" );
    200195
     
    224219                __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
    225220                return;
    226         }
    227         else {
     221        } else {
    228222                __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    229223
     
    259253        // If we haven't left the last level of recursion
    260254        // it means we don't need to do anything
    261         if( this->recursion != 0) {
     255        if ( this->recursion != 0) {
    262256                __cfaabi_dbg_print_safe( "Kernel :  recursion still %d\n", this->recursion);
    263257                unlock( this->lock );
     
    283277static void __dtor_leave( monitor$ * this, bool join ) {
    284278        __cfaabi_dbg_debug_do(
    285                 if( active_thread() != this->owner ) {
     279                if ( active_thread() != this->owner ) {
    286280                        abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, active_thread(), this->owner);
    287281                }
    288                 if( this->recursion != 1  && !join ) {
     282                if ( this->recursion != 1  && !join ) {
    289283                        abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    290284                }
     
    332326// relies on the monitor array being sorted
    333327static inline void enter( __monitor_group_t monitors ) {
    334         for( __lock_size_t i = 0; i < monitors.size; i++) {
     328        for ( i; monitors.size ) {
    335329                __enter( monitors[i], monitors );
    336330        }
     
    340334// relies on the monitor array being sorted
    341335static inline void leave(monitor$ * monitors [], __lock_size_t count) {
    342         for( __lock_size_t i = count - 1; i >= 0; i--) {
     336        for ( i; -~= count - 1 ) {
    343337                __leave( monitors[i] );
    344338        }
     
    454448
    455449        // Create storage for monitor context
    456         monitor_ctx( this.monitors, this.monitor_count );
     450        monitor_ctx( this.monitors, this.monitor_count );       // creates monitors, count, recursions, masks, locks
    457451
    458452        // Create the node specific to this wait operation
     
    477471
    478472        // Remove any duplicate threads
    479         for( __lock_size_t i = 0; i < count; i++) {
     473        for ( i; count ) {
    480474                thread$ * new_owner = next_thread( monitors[i] );
    481475                insert_unique( threads, thread_count, new_owner );
     
    483477
    484478        // Unlock the locks, we don't need them anymore
    485         for(int i = 0; i < count; i++) {
     479        for ( i; count ) {
    486480                unlock( *locks[i] );
    487481        }
    488482
    489483        // Wake the threads
    490         for(int i = 0; i < thread_count; i++) {
     484        for ( i; thread_count ) {
    491485                unpark( threads[i] );
    492486        }
     
    500494
    501495bool signal( condition & this ) libcfa_public {
    502         if( is_empty( this ) ) { return false; }
     496        if ( is_empty( this ) ) { return false; }
    503497
    504498        //Check that everything is as expected
     
    513507                }
    514508
    515                 for(int i = 0; i < this.monitor_count; i++) {
     509                for ( i; this.monitor_count ) {
    516510                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
    517511                                abort( "Signal on condition %p made with different monitor, expected %p got %p", &this, this.monitors[i], this_thrd->monitors[i] );
     
    529523
    530524        //Add the thread to the proper AS stack
    531         for(int i = 0; i < count; i++) {
     525        for ( i; count ) {
    532526                __condition_criterion_t * crit = &node->criteria[i];
    533527                assert( !crit->ready );
     
    542536
    543537bool signal_block( condition & this ) libcfa_public {
    544         if( !this.blocked.head ) { return false; }
     538        if ( !this.blocked.head ) { return false; }
    545539
    546540        //Check that everything is as expected
     
    549543
    550544        // Create storage for monitor context
    551         monitor_ctx( this.monitors, this.monitor_count );
     545        monitor_ctx( this.monitors, this.monitor_count );       // creates monitors, count, recursions, masks, locks
    552546
    553547        // Lock all monitors (aggregates the locks them as well)
    554548        lock_all( monitors, locks, count );
    555 
    556549
    557550        // Create the node specific to this wait operation
     
    576569        park();
    577570
    578 
    579571        // WE WOKE UP
    580 
    581572
    582573        __cfaabi_dbg_print_buffer_local( "Kernel :   signal_block returned\n" );
     
    621612        __cfaabi_dbg_print_buffer_decl( "Kernel : waitfor %"PRIdFAST16" (s: %"PRIdFAST16", m: %"PRIdFAST16")\n", actual_count, mask.size, (__lock_size_t)max);
    622613
    623         if(actual_count == 0) return;
     614        if (actual_count == 0) return;
    624615
    625616        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );
    626617
    627618        // Create storage for monitor context
    628         monitor_ctx( mon_storage, actual_count );
     619        monitor_ctx( mon_storage, actual_count );                       // creates monitors, count, recursions, masks, locks
    629620
    630621        // Lock all monitors (aggregates the locks as well)
     
    636627                [next, index] = search_entry_queue( mask, monitors, count );
    637628
    638                 if( next ) {
     629                if ( next ) {
    639630                        *mask.accepted = index;
    640631                        __acceptable_t& accepted = mask[index];
    641                         if( accepted.is_dtor ) {
     632                        if ( accepted.is_dtor ) {
    642633                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );
    643634                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
     
    662653                                __cfaabi_dbg_print_buffer_local( "Kernel :  baton of %"PRIdFAST16" monitors : ", count );
    663654                                #ifdef __CFA_DEBUG_PRINT__
    664                                         for( int i = 0; i < count; i++) {
     655                                        for ( i; count ) {
    665656                                                __cfaabi_dbg_print_buffer_local( "%p %p ", monitors[i], monitors[i]->signal_stack.top );
    666657                                        }
     
    692683
    693684
    694         if( duration == 0 ) {
     685        if ( duration == 0 ) {
    695686                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" );
    696687
     
    712703        set_mask( monitors, count, mask );
    713704
    714         for( __lock_size_t i = 0; i < count; i++) {
     705        for ( i; count ) {
    715706                verify( monitors[i]->owner == active_thread() );
    716707        }
     
    752743        monitors[0]->owner        = owner;
    753744        monitors[0]->recursion    = 1;
    754         for( __lock_size_t i = 1; i < count; i++ ) {
     745        for ( i; 1~count ) {
    755746                /* paranoid */ verify ( monitors[i]->lock.lock );
    756747                /* paranoid */ verifyf( monitors[i]->owner == active_thread(), "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), monitors[i]->owner, monitors[i]->recursion, monitors[i] );
     
    761752
    762753static inline void set_mask( monitor$ * storage [], __lock_size_t count, const __waitfor_mask_t & mask ) {
    763         for( __lock_size_t i = 0; i < count; i++) {
     754        for ( i; count) {
    764755                storage[i]->mask = mask;
    765756        }
     
    776767        __cfaabi_dbg_print_safe( "Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    777768        __condition_criterion_t * urgent = pop( this->signal_stack );
    778         if( urgent ) {
     769        if ( urgent ) {
    779770                //The signaller stack is not empty,
    780771                //regardless of if we are ready to baton pass,
     
    801792
    802793        // Check if there are any acceptable functions
    803         if( !it ) return false;
     794        if ( !it ) return false;
    804795
    805796        // If this isn't the first monitor to test this, there is no reason to repeat the test.
    806         if( this != group[0] ) return group[0]->mask.accepted >= 0;
     797        if ( this != group[0] ) return group[0]->mask.accepted >= 0;
    807798
    808799        // For all acceptable functions check if this is the current function.
    809         for( __lock_size_t i = 0; i < count; i++, it++ ) {
    810                 if( *it == group ) {
     800        for ( __lock_size_t i = 0; i < count; i++, it++ ) {
     801                if ( *it == group ) {
    811802                        *this->mask.accepted = i;
    812803                        return true;
     
    819810
    820811static inline void init( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    821         for( __lock_size_t i = 0; i < count; i++) {
     812        for ( i; count ) {
    822813                (criteria[i]){ monitors[i], waiter };
    823814        }
     
    827818
    828819static inline void init_push( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    829         for( __lock_size_t i = 0; i < count; i++) {
     820        for ( i; count ) {
    830821                (criteria[i]){ monitors[i], waiter };
    831822                __cfaabi_dbg_print_safe( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
     
    837828
    838829static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    839         for( __lock_size_t i = 0; i < count; i++ ) {
     830        for ( i; count ) {
    840831                lock( *locks[i] __cfaabi_dbg_ctx2 );
    841832        }
     
    843834
    844835static inline void lock_all( monitor$ * source [], __spinlock_t * /*out*/ locks [], __lock_size_t count ) {
    845         for( __lock_size_t i = 0; i < count; i++ ) {
     836        for ( i; count ) {
    846837                __spinlock_t * l = &source[i]->lock;
    847838                lock( *l __cfaabi_dbg_ctx2 );
    848                 if(locks) locks[i] = l;
     839                if (locks) locks[i] = l;
    849840        }
    850841}
    851842
    852843static inline void unlock_all( __spinlock_t * locks [], __lock_size_t count ) {
    853         for( __lock_size_t i = 0; i < count; i++ ) {
     844        for ( i; count ) {
    854845                unlock( *locks[i] );
    855846        }
     
    857848
    858849static inline void unlock_all( monitor$ * locks [], __lock_size_t count ) {
    859         for( __lock_size_t i = 0; i < count; i++ ) {
     850        for ( i; count ) {
    860851                unlock( locks[i]->lock );
    861852        }
     
    869860        __waitfor_mask_t /*out*/ masks []
    870861) {
    871         for( __lock_size_t i = 0; i < count; i++ ) {
     862        for ( i; count ) {
    872863                recursions[i] = ctx[i]->recursion;
    873                 masks[i]      = ctx[i]->mask;
     864                masks[i] = ctx[i]->mask;
    874865        }
    875866}
     
    883874) {
    884875        lock_all( locks, count );
    885         for( __lock_size_t i = 0; i < count; i++ ) {
     876        for ( i; count ) {
    886877                ctx[i]->recursion = recursions[i];
    887                 ctx[i]->mask      = masks[i];
     878                ctx[i]->mask = masks[i];
    888879        }
    889880        unlock_all( locks, count );
     
    901892        bool ready2run = true;
    902893
    903         for(    int i = 0; i < count; i++ ) {
    904 
     894        for ( i; count ) {
    905895                // __cfaabi_dbg_print_safe( "Checking %p for %p\n", &criteria[i], target );
    906                 if( &criteria[i] == target ) {
     896                if ( &criteria[i] == target ) {
    907897                        criteria[i].ready = true;
    908898                        // __cfaabi_dbg_print_safe( "True\n" );
     
    918908static inline void brand_condition( condition & this ) {
    919909        thread$ * thrd = active_thread();
    920         if( !this.monitors ) {
     910        if ( !this.monitors ) {
    921911                // __cfaabi_dbg_print_safe( "Branding\n" );
    922912                assertf( thrd->monitors.data != 0p, "No current monitor to brand condition %p", thrd->monitors.data );
     
    924914
    925915                this.monitors = (monitor$ **)malloc( this.monitor_count * sizeof( *this.monitors ) );
    926                 for( int i = 0; i < this.monitor_count; i++ ) {
     916                for ( i; this.monitor_count ) {
    927917                        this.monitors[i] = thrd->monitors[i];
    928918                }
     
    947937                // For each acceptable check if it matches
    948938                int i = 0;
    949                 __acceptable_t * end   = end  (mask);
     939                __acceptable_t * end = end(mask);
    950940                __acceptable_t * begin = begin(mask);
    951941                for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
     
    961951                #endif
    962952        }
    963 #endif
    964         int i = 0;
    965         __acceptable_t * end   = end  (mask);
    966         __acceptable_t * begin = begin(mask);
     953#else
    967954        // For each acceptable (respect lexical priority in waitfor statement)
    968         for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
     955        __acceptable_t * it = end(mask); it--;                          // end is passed the last node, so backup
     956        for ( int i = mask.size - 1; i >= 0; i -= 1, it-- ) {
    969957                #if defined( __CFA_WITH_VERIFY__ )
    970958                thread$ * last = 0p;
     
    980968                        // For each thread in the entry-queue check for a match
    981969                        if ( *it == curr->monitors ) {
    982                                 // If match, return it after removeing from the entry queue
     970                                // If match, return it after removing from the entry queue
    983971                                return [remove( entry_queue, thrd_it ), i];
    984972                        } // if
     
    989977                } // for
    990978        } // for
     979#endif
    991980        return [0, -1];
    992981}
    993982
    994 forall(T & | sized( T ))
     983forall( T & | sized( T ) )
    995984static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ) {
    996         if( !val ) return size;
    997 
    998         for( __lock_size_t i = 0; i <= size; i++) {
    999                 if( array[i] == val ) return size;
     985        if ( ! val ) return size;
     986
     987        for ( __lock_size_t i; ~= size ) {
     988                if ( array[i] == val ) return size;
    1000989        }
    1001990
    1002991        array[size] = val;
    1003         size = size + 1;
    1004         return size;
     992        return size += 1;
    1005993}
    1006994
    1007995static inline __lock_size_t count_max( const __waitfor_mask_t & mask ) {
    1008996        __lock_size_t max = 0;
    1009         for( __lock_size_t i = 0; i < mask.size; i++ ) {
     997        for ( i; mask.size ) {
    1010998                __acceptable_t & accepted = mask[i];
    1011999                max += accepted.size;
     
    10161004static inline __lock_size_t aggregate( monitor$ * storage [], const __waitfor_mask_t & mask ) {
    10171005        __lock_size_t size = 0;
    1018         for( __lock_size_t i = 0; i < mask.size; i++ ) {
     1006        for ( i; mask.size ) {
    10191007                __acceptable_t & accepted = mask[i];
    10201008                __libcfa_small_sort( accepted.data, accepted.size );
    1021                 for( __lock_size_t j = 0; j < accepted.size; j++) {
     1009                for ( __lock_size_t j = 0; j < accepted.size; j++) {
    10221010                        insert_unique( storage, size, accepted[j] );
    10231011                }
     
    10401028        __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    10411029
    1042         if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
     1030        if ( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
    10431031                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
    1044         }
    1045         else if( !this->owner ) {
     1032        } else if ( !this->owner ) {
    10461033                // No one has the monitor, just take it
    10471034                __set_owner( this, thrd );
    10481035
    10491036                __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
    1050         }
    1051         else if( this->owner == thrd) {
     1037        } else if ( this->owner == thrd) {
    10521038                // We already have the monitor, just note how many times we took it
    10531039                this->recursion += 1;
    10541040
    10551041                __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
    1056         }
    1057         else {
     1042        } else {
    10581043                __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    10591044
  • libcfa/src/rational.cfa

    r956b389 r3e2e9b2  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 11 22:37:12 2024
    13 // Update Count     : 206
     12// Last Modified On : Wed Nov 27 18:06:43 2024
     13// Update Count     : 208
    1414//
    1515
     
    1919
    2020#pragma GCC visibility push(default)
     21
     22// Arithmetic, Relational
    2123
    2224forall( T | arithmetic( T ) ) {
     
    190192                return l = l / r;
    191193        } // ?/?
    192 
    193         // I/O
    194 
    195         forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
     194} // distribution
     195
     196// I/O
     197
     198forall( T ) {
     199        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | arithmetic( T ) )
    196200        istype & ?|?( istype & is, rational(T) & r ) {
    197201                is | r.numerator | r.denominator;
     
    210214} // distribution
    211215
     216// Exponentiation
     217
    212218forall( T | arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    213219        rational(T) ?\?( rational(T) x, long int y ) {
     
    224230} // distribution
    225231
    226 // conversion
     232// Conversion
    227233
    228234forall( T | arithmetic( T ) | { double convert( T ); } )
  • libcfa/src/rational.hfa

    r956b389 r3e2e9b2  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Fri Nov  8 17:02:09 2024
    15 // Update Count     : 126
     14// Last Modified On : Wed Nov 27 18:11:07 2024
     15// Update Count     : 128
    1616//
    1717
     
    2121#include "math.trait.hfa"                                                               // arithmetic
    2222
    23 // implementation
     23// Implementation
    2424
    2525forall( T ) {
     
    2828        }; // rational
    2929}
     30
     31// Arithmetic, Relational
    3032
    3133forall( T | arithmetic( T ) ) {
     
    7375        rational(T) ?/?( rational(T) l, rational(T) r );
    7476        rational(T) ?/=?( rational(T) & l, rational(T) r );
     77} // distribution
    7578
    76         // I/O
    77         forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
     79// I/O
     80
     81forall( T ) {
     82        forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } | arithmetic( T ) )
    7883        istype & ?|?( istype &, rational(T) & );
    7984
     
    8489} // distribution
    8590
     91// Exponentiation
     92
    8693forall( T | arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
    8794        rational(T) ?\?( rational(T) x, long int y );
     
    8996} // distribution
    9097
    91 // conversion
     98// Conversion
     99
    92100forall( T | arithmetic( T ) | { double convert( T ); } )
    93101double widen( rational(T) r );
  • tests/.expect/KRfunctions.arm64.txt

    r956b389 r3e2e9b2  
    104104    signed int _X1bi_2;
    105105    {
    106         signed int *(*_tmp_cp_ret6)(signed int __param_0, signed int __param_1);
    107         ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret6=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret6)));
     106        signed int *(*_tmp_cp_ret0)(signed int __param_0, signed int __param_1);
     107        ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret0=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret0)));
    108108    }
    109109
  • tests/.expect/KRfunctions.x64.txt

    r956b389 r3e2e9b2  
    104104    signed int _X1bi_2;
    105105    {
    106         signed int *(*_tmp_cp_ret6)(signed int __param_0, signed int __param_1);
    107         ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret6=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret6)));
     106        signed int *(*_tmp_cp_ret0)(signed int __param_0, signed int __param_1);
     107        ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret0=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret0)));
    108108    }
    109109
  • tests/.expect/KRfunctions.x86.txt

    r956b389 r3e2e9b2  
    104104    signed int _X1bi_2;
    105105    {
    106         signed int *(*_tmp_cp_ret6)(signed int __param_0, signed int __param_1);
    107         ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret6=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret6)));
     106        signed int *(*_tmp_cp_ret0)(signed int __param_0, signed int __param_1);
     107        ((void)(_X1xFPi_ii__2=(((void)(_tmp_cp_ret0=_X3f10FFPi_ii__iPiPid__1(3, (&_X1ai_2), (&_X1bi_2), 3.5))) , _tmp_cp_ret0)));
    108108    }
    109109
  • tests/.expect/declarationSpecifier.arm64.txt

    r956b389 r3e2e9b2  
    10591059    }
    10601060
    1061     signed int _tmp_cp_ret6;
    1062     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     1061    signed int _tmp_cp_ret0;
     1062    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    10631063    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    10641064        {
  • tests/.expect/declarationSpecifier.x64.txt

    r956b389 r3e2e9b2  
    10591059    }
    10601060
    1061     signed int _tmp_cp_ret6;
    1062     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     1061    signed int _tmp_cp_ret0;
     1062    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    10631063    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    10641064        {
  • tests/.expect/declarationSpecifier.x86.txt

    r956b389 r3e2e9b2  
    10591059    }
    10601060
    1061     signed int _tmp_cp_ret6;
    1062     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     1061    signed int _tmp_cp_ret0;
     1062    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    10631063    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    10641064        {
  • tests/.expect/extension.arm64.txt

    r956b389 r3e2e9b2  
    457457
    458458    {
    459         signed int _tmp_cp_ret6;
    460         ((void)(((void)(_tmp_cp_ret6=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret6));
     459        signed int _tmp_cp_ret0;
     460        ((void)(((void)(_tmp_cp_ret0=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret0));
    461461    }
    462462
  • tests/.expect/extension.x64.txt

    r956b389 r3e2e9b2  
    457457
    458458    {
    459         signed int _tmp_cp_ret6;
    460         ((void)(((void)(_tmp_cp_ret6=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret6));
     459        signed int _tmp_cp_ret0;
     460        ((void)(((void)(_tmp_cp_ret0=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret0));
    461461    }
    462462
  • tests/.expect/extension.x86.txt

    r956b389 r3e2e9b2  
    457457
    458458    {
    459         signed int _tmp_cp_ret6;
    460         ((void)(((void)(_tmp_cp_ret6=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret6));
     459        signed int _tmp_cp_ret0;
     460        ((void)(((void)(_tmp_cp_ret0=__extension__ _X4fredFi_i__1(3))) , _tmp_cp_ret0));
    461461    }
    462462
  • tests/.expect/gccExtensions.arm64.txt

    r956b389 r3e2e9b2  
    339339    }
    340340
    341     signed int _tmp_cp_ret6;
    342     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     341    signed int _tmp_cp_ret0;
     342    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    343343    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    344344        {
  • tests/.expect/gccExtensions.x64.txt

    r956b389 r3e2e9b2  
    339339    }
    340340
    341     signed int _tmp_cp_ret6;
    342     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     341    signed int _tmp_cp_ret0;
     342    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    343343    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    344344        {
  • tests/.expect/gccExtensions.x86.txt

    r956b389 r3e2e9b2  
    317317    }
    318318
    319     signed int _tmp_cp_ret6;
    320     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
     319    signed int _tmp_cp_ret0;
     320    signed int _X3reti_2 = (((void)(_tmp_cp_ret0=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret0);
    321321    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
    322322        {
Note: See TracChangeset for help on using the changeset viewer.