Changes in / [3e5dd913:53449a4]
- Files:
-
- 13 edited
-
libcfa/src/bits/collection.hfa (modified) (5 diffs)
-
libcfa/src/bits/containers.hfa (modified) (1 diff)
-
libcfa/src/bits/defs.hfa (modified) (1 diff)
-
libcfa/src/bits/queue.hfa (modified) (3 diffs)
-
libcfa/src/bits/sequence.hfa (modified) (7 diffs)
-
libcfa/src/bits/stack.hfa (modified) (3 diffs)
-
libcfa/src/concurrency/invoke.h (modified) (2 diffs)
-
libcfa/src/concurrency/locks.cfa (modified) (5 diffs)
-
libcfa/src/concurrency/locks.hfa (modified) (2 diffs)
-
libcfa/src/concurrency/thread.cfa (modified) (1 diff)
-
tests/queue.cfa (modified) (2 diffs)
-
tests/sequence.cfa (modified) (2 diffs)
-
tests/stack.cfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/collection.hfa
r3e5dd913 r53449a4 1 1 #pragma once 2 #include <stdio.h> // REMOVE THIS AFTER DEBUGGING 3 2 4 3 5 struct Colable { 4 Colable * next; // next node in the list6 struct Colable * next; // next node in the list 5 7 // invariant: (next != 0) <=> listed() 6 8 }; 7 8 inline {9 #ifdef __cforall 10 static inline { 9 11 // PUBLIC 10 12 … … 28 30 } 29 31 30 // wrappers to make Collection have T31 forall( dtype T ) {32 T *& Next( T * n ) {33 return (T *)Next( (Colable *)n );34 }32 // // wrappers to make Collection have T 33 // forall( dtype T ) { 34 // T *& Next( T * n ) { 35 // return (T *)Next( (Colable *)n ); 36 // } 35 37 36 bool listed( T * n ) {37 return Next( (Colable *)n ) != 0p;38 }39 } // distribution38 // bool listed( T * n ) { 39 // return Next( (Colable *)n ) != 0p; 40 // } 41 // } // distribution 40 42 } // distribution 41 43 … … 45 47 }; 46 48 47 inline {49 static inline { 48 50 // class invariant: root == 0 & empty() | *root in *this 49 51 void ?{}( Collection &, const Collection & ) = void; // no copy … … 68 70 }; 69 71 70 inline {72 static inline { 71 73 void ?{}( ColIter & colIter ) with( colIter ) { 72 74 curr = 0p; … … 79 81 } // distribution 80 82 } // distribution 83 #endif -
libcfa/src/bits/containers.hfa
r3e5dd913 r53449a4 36 36 #define __small_array_t(T) __small_array(T) 37 37 #else 38 #define __small_array_t(T) struct__small_array38 #define __small_array_t(T) __small_array 39 39 #endif 40 40 -
libcfa/src/bits/defs.hfa
r3e5dd913 r53449a4 29 29 #define __cfa_anonymous_object(x) inline struct x 30 30 #else 31 #define __cfa_anonymous_object(x) x __cfa_anonymous_object31 #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object 32 32 #endif 33 33 -
libcfa/src/bits/queue.hfa
r3e5dd913 r53449a4 3 3 #include "bits/collection.hfa" 4 4 5 forall( dtype T ) {5 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) { 6 6 struct Queue { 7 7 inline Collection; // Plan 9 inheritance … … 64 64 T & t = head( q ); 65 65 if ( root ) { 66 root = Next( root );66 root = Next( (T *)root ); 67 67 if ( &head( q ) == &t ) { 68 68 root = last = 0p; // only one element … … 142 142 } // distribution 143 143 144 forall( dtype T ) {144 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) { 145 145 struct QueueIter { 146 146 inline ColIter; // Plan 9 inheritance -
libcfa/src/bits/sequence.hfa
r3e5dd913 r53449a4 2 2 3 3 #include "bits/collection.hfa" 4 #include "bits/defs.hfa" 4 5 5 6 struct Seqable { 6 inline Colable;7 Seqable * back; // pointer to previous node in the list7 __cfa_anonymous_object(Colable); 8 struct Seqable * back; // pointer to previous node in the list 8 9 }; 9 10 10 inline { 11 #ifdef __cforall 12 static inline { 11 13 // PUBLIC 12 14 … … 26 28 } 27 29 28 // wrappers to make Collection have T29 forall( dtype T ) {30 T *& Back( T * n ) {31 return (T *)Back( (Seqable *)n );32 }33 } // distribution30 // // wrappers to make Collection have T 31 // forall( dtype T ) { 32 // T *& Back( T * n ) { 33 // return (T *)Back( (Seqable *)n ); 34 // } 35 // } // distribution 34 36 } // distribution 35 37 36 forall( dtype T ) {38 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) { 37 39 struct Sequence { 38 40 inline Collection; // Plan 9 inheritance 39 41 }; 40 42 41 inline {43 static inline { 42 44 // wrappers to make Collection have T 43 45 T & head( Sequence(T) & s ) with( s ) { … … 184 186 T * toEnd = Back( &head( s ) ); 185 187 T * fromEnd = Back( &head( from ) ); 186 Back( root ) = fromEnd;188 Back( (T *)root ) = fromEnd; 187 189 Next( fromEnd ) = &head( s ); 188 Back( from.root ) = toEnd;190 Back( (T *)from.root ) = toEnd; 189 191 Next( toEnd ) = &head( from ); 190 192 } // if … … 214 216 } // distribution 215 217 216 forall( dtype T ) {218 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) { 217 219 // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order. 218 220 struct SeqIter { … … 224 226 }; 225 227 226 inline {228 static inline { 227 229 void ?{}( SeqIter(T) & si ) with( si ) { 228 230 ((ColIter &)si){}; … … 265 267 }; 266 268 267 inline {269 static inline { 268 270 void ?{}( SeqIterRev(T) & si ) with( si ) { 269 271 ((ColIter &)si){}; … … 298 300 } // distribution 299 301 } // distribution 302 303 #endif -
libcfa/src/bits/stack.hfa
r3e5dd913 r53449a4 3 3 #include "bits/collection.hfa" 4 4 5 forall( dtype T ) {5 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) { 6 6 struct Stack { 7 7 inline Collection; // Plan 9 inheritance … … 44 44 T & t = head( s ); 45 45 if ( root ) { 46 root = ( T *)Next( root );46 root = ( T *)Next( (T *)root ); 47 47 if ( &head( s ) == &t ) root = 0p; // only one element ? 48 48 Next( &t ) = 0p; … … 58 58 59 59 60 forall( dtype T ) {60 forall( dtype T | { T *& Next ( T * ); bool listed ( T * ); } ) { 61 61 struct StackIter { 62 62 inline ColIter; // Plan 9 inheritance -
libcfa/src/concurrency/invoke.h
r3e5dd913 r53449a4 189 189 struct __monitor_group_t monitors; 190 190 191 // used to put threads on user data structures 192 struct { 193 struct $thread * next; 194 struct $thread * back; 195 } seqable; 196 191 197 struct { 192 198 struct $thread * next; … … 218 224 } 219 225 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 220 238 static inline void ?{}(__monitor_group_t & this) { 221 239 (this.data){0p}; -
libcfa/src/concurrency/locks.cfa
r3e5dd913 r53449a4 29 29 30 30 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 } 31 43 } 32 44 … … 58 70 abort("A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock."); 59 71 } else if ( owner != 0p && owner != active_thread() ) { 60 a ppend( blocked_threads,active_thread() );72 addTail( blocked_threads, *active_thread() ); 61 73 wait_count++; 62 74 unlock( lock ); … … 96 108 97 109 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 98 $thread * t = pop_head( blocked_threads );110 $thread * t = &dropHead( blocked_threads ); 99 111 owner = t; 100 112 recursion_count = ( t ? 1 : 0 ); … … 128 140 lock( lock __cfaabi_dbg_ctx2 ); 129 141 if ( owner != 0p ) { 130 a ppend( blocked_threads,t );142 addTail( blocked_threads, *t ); 131 143 wait_count++; 132 144 unlock( lock ); … … 257 269 size_t recursion_count = 0; 258 270 if (i->lock) { 259 i->t->link.next = 1p;260 271 recursion_count = get_recursion_count(*i->lock); 261 272 remove_( *i->lock ); -
libcfa/src/concurrency/locks.hfa
r3e5dd913 r53449a4 43 43 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info ); 44 44 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 ); 45 49 } 46 50 … … 64 68 65 69 // List of blocked threads 66 __queue_t( $thread ) blocked_threads;70 Sequence( $thread ) blocked_threads; 67 71 68 72 // Count of current blocked threads -
libcfa/src/concurrency/thread.cfa
r3e5dd913 r53449a4 43 43 canary = 0x0D15EA5E0D15EA5Ep; 44 44 #endif 45 46 seqable.next = 0p; 47 seqable.back = 0p; 45 48 46 49 node.next = 0p; -
tests/queue.cfa
r3e5dd913 r53449a4 13 13 void ?{}( Fred & fred, int p ) with( fred ) { 14 14 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; 15 22 } 16 23 … … 68 75 } 69 76 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 70 85 Queue(Mary) mary; 71 86 QueueIter(Mary) maryIter = { mary }; -
tests/sequence.cfa
r3e5dd913 r53449a4 13 13 void ?{}( Fred & fred, int p ) with( fred ) { 14 14 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; 15 27 } 16 28 … … 76 88 } 77 89 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 78 102 Sequence(Mary) mary; 79 103 Sequence(Mary) baz; -
tests/stack.cfa
r3e5dd913 r53449a4 13 13 void ?{}( Fred & fred, int p ) with( fred ) { 14 14 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; 15 22 } 16 23 … … 68 75 } 69 76 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 70 85 Stack(Mary) mary; 71 86 StackIter(Mary) maryIter = { mary };
Note:
See TracChangeset
for help on using the changeset viewer.