Changes in / [53449a4:3e5dd913]


Ignore:
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/collection.hfa

    r53449a4 r3e5dd913  
    11#pragma once
    2 #include <stdio.h> // REMOVE THIS AFTER DEBUGGING
    3 
    42
    53struct Colable {
    6         struct Colable * next;                                                                          // next node in the list
     4        Colable * next;                                                                         // next node in the list
    75        // invariant: (next != 0) <=> listed()
    86};
    9 #ifdef __cforall
    10 static inline {
     7
     8inline {
    119        // PUBLIC
    1210
     
    3028        }
    3129
    32         // // wrappers to make Collection have T
    33         // forall( dtype T ) {
    34         //      T *& Next( T * n ) {
    35         //              return (T *)Next( (Colable *)n );
    36         //      }
     30        // wrappers to make Collection have T
     31        forall( dtype T ) {
     32                T *& Next( T * n ) {
     33                        return (T *)Next( (Colable *)n );
     34                }
    3735
    38         //      bool listed( T * n ) {
    39         //              return Next( (Colable *)n ) != 0p;
    40         //      }
    41         // } // distribution
     36                bool listed( T * n ) {
     37                        return Next( (Colable *)n ) != 0p;
     38                }
     39        } // distribution
    4240} // distribution
    4341
     
    4745};
    4846
    49 static inline {
     47inline {
    5048        // class invariant: root == 0 & empty() | *root in *this
    5149        void ?{}( Collection &, const Collection & ) = void; // no copy
     
    7068};
    7169
    72 static inline {
     70inline {
    7371        void ?{}( ColIter & colIter ) with( colIter ) {
    7472                curr = 0p;
     
    8179        } // distribution
    8280} // distribution
    83 #endif
  • libcfa/src/bits/containers.hfa

    r53449a4 r3e5dd913  
    3636        #define __small_array_t(T) __small_array(T)
    3737#else
    38         #define __small_array_t(T) __small_array
     38        #define __small_array_t(T) struct __small_array
    3939#endif
    4040
  • libcfa/src/bits/defs.hfa

    r53449a4 r3e5dd913  
    2929#define __cfa_anonymous_object(x) inline struct x
    3030#else
    31 #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
     31#define __cfa_anonymous_object(x) x __cfa_anonymous_object
    3232#endif
    3333
  • libcfa/src/bits/queue.hfa

    r53449a4 r3e5dd913  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
     5forall( dtype T ) {
    66        struct Queue {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    6464                        T & t = head( q );
    6565                        if ( root ) {
    66                                 root = Next( (T *)root );
     66                                root = Next( root );
    6767                                if ( &head( q ) == &t ) {
    6868                                        root = last = 0p;                                       // only one element
     
    142142} // distribution
    143143
    144 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
     144forall( dtype T ) {
    145145        struct QueueIter {
    146146                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/bits/sequence.hfa

    r53449a4 r3e5dd913  
    22
    33#include "bits/collection.hfa"
    4 #include "bits/defs.hfa"
    54
    65struct Seqable {
    7         __cfa_anonymous_object(Colable);
    8         struct Seqable * back;                                                                          // pointer to previous node in the list
     6        inline Colable;
     7        Seqable * back;                                                                         // pointer to previous node in the list
    98};
    109
    11 #ifdef __cforall
    12 static inline {
     10inline {
    1311        // PUBLIC
    1412
     
    2826        }
    2927
    30         // // wrappers to make Collection have T
    31         // forall( dtype T ) {
    32         //      T *& Back( T * n ) {
    33         //              return (T *)Back( (Seqable *)n );
    34         //      }
    35         // } // distribution
     28        // wrappers to make Collection have T
     29        forall( dtype T ) {
     30                T *& Back( T * n ) {
     31                        return (T *)Back( (Seqable *)n );
     32                }
     33        } // distribution
    3634} // distribution
    3735
    38 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) {
     36forall( dtype T ) {
    3937        struct Sequence {
    4038                inline Collection;                                                              // Plan 9 inheritance
    4139        };
    4240
    43         static inline {
     41        inline {
    4442                // wrappers to make Collection have T
    4543                T & head( Sequence(T) & s ) with( s ) {
     
    186184                                T * toEnd = Back( &head( s ) );
    187185                                T * fromEnd = Back( &head( from ) );
    188                                 Back( (T *)root ) = fromEnd;
     186                                Back( root ) = fromEnd;
    189187                                Next( fromEnd ) = &head( s );
    190                                 Back( (T *)from.root ) = toEnd;
     188                                Back( from.root ) = toEnd;
    191189                                Next( toEnd ) = &head( from );
    192190                        } // if
     
    216214} // distribution
    217215
    218 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) {
     216forall( dtype T ) {
    219217        // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order.
    220218        struct SeqIter {
     
    226224        };
    227225
    228         static inline {
     226        inline {
    229227                void ?{}( SeqIter(T) & si ) with( si ) {
    230228                        ((ColIter &)si){};
     
    267265        };
    268266
    269         static inline {
     267        inline {
    270268                void ?{}( SeqIterRev(T) & si ) with( si ) {     
    271269                        ((ColIter &)si){};
     
    300298        } // distribution
    301299} // distribution
    302 
    303 #endif
  • libcfa/src/bits/stack.hfa

    r53449a4 r3e5dd913  
    33#include "bits/collection.hfa"
    44
    5 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
     5forall( dtype T ) {
    66        struct Stack {
    77                inline Collection;                                                              // Plan 9 inheritance
     
    4444                        T & t = head( s );
    4545                        if ( root ) {
    46                                 root = ( T *)Next( (T *)root );
     46                                root = ( T *)Next( root );
    4747                                if ( &head( s ) == &t ) root = 0p;              // only one element ?
    4848                                Next( &t ) = 0p;
     
    5858
    5959
    60 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) {
     60forall( dtype T ) {
    6161        struct StackIter {
    6262                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/concurrency/invoke.h

    r53449a4 r3e5dd913  
    189189                struct __monitor_group_t monitors;
    190190
    191                 // used to put threads on user data structures
    192                 struct {
    193                         struct $thread * next;
    194                         struct $thread * back;
    195                 } seqable;
    196 
    197191                struct {
    198192                        struct $thread * next;
     
    224218                }
    225219
    226                 static inline $thread *& Back( $thread * this ) __attribute__((const)) {
    227                         return this->seqable.back;
    228                 }
    229 
    230                 static inline $thread *& Next( $thread * this ) __attribute__((const)) {
    231                         return this->seqable.next;
    232                 }
    233 
    234                 static inline bool listed( $thread * this ) {
    235                         return this->seqable.next != 0p;
    236                 }
    237 
    238220                static inline void ?{}(__monitor_group_t & this) {
    239221                        (this.data){0p};
  • libcfa/src/concurrency/locks.cfa

    r53449a4 r3e5dd913  
    2929
    3030        void ^?{}( info_thread(L) & this ){ }
    31 
    32         info_thread(L) *& Back( info_thread(L) * this ) {
    33                 return (info_thread(L) *)Back( (Seqable *)this );
    34         }
    35 
    36         info_thread(L) *& Next( info_thread(L) * this ) {
    37                 return (info_thread(L) *)Next( (Colable *)this );
    38         }
    39 
    40         bool listed( info_thread(L) * this ) {
    41                 return Next( (Colable *)this ) != 0p;
    42         }
    4331}
    4432
     
    7058                abort("A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock.");
    7159        } else if ( owner != 0p && owner != active_thread() ) {
    72                 addTail( blocked_threads, *active_thread() );
     60                append( blocked_threads, active_thread() );
    7361                wait_count++;
    7462                unlock( lock );
     
    10896
    10997void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    110         $thread * t = &dropHead( blocked_threads );
     98        $thread * t = pop_head( blocked_threads );
    11199        owner = t;
    112100        recursion_count = ( t ? 1 : 0 );
     
    140128    lock( lock __cfaabi_dbg_ctx2 );
    141129        if ( owner != 0p ) {
    142                 addTail( blocked_threads, *t );
     130                append( blocked_threads, t );
    143131                wait_count++;
    144132                unlock( lock );
     
    269257                size_t recursion_count = 0;
    270258                if (i->lock) {
     259                        i->t->link.next = 1p;
    271260                        recursion_count = get_recursion_count(*i->lock);
    272261                        remove_( *i->lock );
  • libcfa/src/concurrency/locks.hfa

    r53449a4 r3e5dd913  
    4343        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info );
    4444        void ^?{}( info_thread(L) & this );
    45 
    46         info_thread(L) *& Back( info_thread(L) * this );
    47         info_thread(L) *& Next( info_thread(L) * this );
    48         bool listed( info_thread(L) * this );
    4945}
    5046
     
    6864
    6965        // List of blocked threads
    70         Sequence( $thread ) blocked_threads;
     66        __queue_t( $thread ) blocked_threads;
    7167
    7268        // Count of current blocked threads
  • libcfa/src/concurrency/thread.cfa

    r53449a4 r3e5dd913  
    4343                canary = 0x0D15EA5E0D15EA5Ep;
    4444        #endif
    45 
    46         seqable.next = 0p;
    47         seqable.back = 0p;
    4845
    4946        node.next = 0p;
  • tests/queue.cfa

    r53449a4 r3e5dd913  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16         Fred *& Next( Fred * n ) {
    17                 return (Fred *)Next( (Colable *)n );
    18         }
    19 
    20         bool listed( Fred * n ) {
    21                 return Next( (Colable *)n ) != 0p;
    2215        }
    2316
     
    7568        }
    7669
    77         Mary *& Next( Mary * n ) {
    78                 return (Mary *)Next( (Colable *)n );
    79         }
    80 
    81         bool listed( Mary * n ) {
    82                 return Next( (Colable *)n ) != 0p;
    83         }
    84 
    8570        Queue(Mary) mary;
    8671        QueueIter(Mary) maryIter = { mary };
  • tests/sequence.cfa

    r53449a4 r3e5dd913  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16 
    17         Fred *& Back( Fred * n ) {
    18                 return (Fred *)Back( (Seqable *)n );
    19         }
    20 
    21         Fred *& Next( Fred * n ) {
    22                 return (Fred *)Next( (Colable *)n );
    23         }
    24 
    25         bool listed( Fred * n ) {
    26                 return Next( (Colable *)n ) != 0p;
    2715        }
    2816
     
    8876        }
    8977
    90         Mary *& Back( Mary * n ) {
    91                 return (Mary *)Back( (Seqable *)n );
    92         }
    93 
    94         Mary *& Next( Mary * n ) {
    95                 return (Mary *)Next( (Colable *)n );
    96         }
    97 
    98         bool listed( Mary * n ) {
    99                 return Next( (Colable *)n ) != 0p;
    100         }
    101 
    10278        Sequence(Mary) mary;
    10379        Sequence(Mary) baz;
  • tests/stack.cfa

    r53449a4 r3e5dd913  
    1313        void ?{}( Fred & fred, int p ) with( fred ) {
    1414                i = p;
    15         }
    16         Fred *& Next( Fred * n ) {
    17                 return (Fred *)Next( (Colable *)n );
    18         }
    19 
    20         bool listed( Fred * n ) {
    21                 return Next( (Colable *)n ) != 0p;
    2215        }
    2316
     
    7568        }
    7669
    77         Mary *& Next( Mary * n ) {
    78                 return (Mary *)Next( (Colable *)n );
    79         }
    80 
    81         bool listed( Mary * n ) {
    82                 return Next( (Colable *)n ) != 0p;
    83         }
    84 
    8570        Stack(Mary) mary;
    8671        StackIter(Mary) maryIter = { mary };
Note: See TracChangeset for help on using the changeset viewer.