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