Changes in / [bae0d35:53692b3]
- Location:
- libcfa/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/defs.hfa
rbae0d35 r53692b3 31 31 #ifdef __cforall 32 32 #define __cfa_anonymous_object(x) inline struct x 33 #define __cfa_dlink(x) inline dlink(x)34 33 #else 35 34 #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object 36 #define __cfa_dlink(x) struct { struct x * next; struct x * back; } __dlink_substitute37 35 #endif 38 36 -
libcfa/src/bits/weakso_locks.hfa
rbae0d35 r53692b3 21 21 #include "bits/sequence.hfa" 22 22 #include "bits/containers.hfa" 23 #include "containers/list.hfa"24 23 25 24 struct $thread; … … 32 31 33 32 // List of blocked threads 34 dlist( $thread ) blocked_threads;33 Sequence( $thread ) blocked_threads; 35 34 36 35 // Count of current blocked threads -
libcfa/src/concurrency/invoke.h
rbae0d35 r53692b3 20 20 21 21 #ifdef __cforall 22 #include "containers/list.hfa"23 22 extern "C" { 24 23 #endif … … 199 198 } seqable; 200 199 201 // used to put threads on dlist data structure202 __cfa_dlink($thread);203 204 200 struct { 205 201 struct $thread * next; … … 213 209 #endif 214 210 }; 215 #ifdef __cforall216 P9_EMBEDDED( $thread, dlink($thread) )217 #endif218 211 // Wrapper for gdb 219 212 struct cfathread_thread_t { struct $thread debug; }; … … 245 238 246 239 static inline $thread *& Next( $thread * this ) __attribute__((const)) { 247 240 return this->seqable.next; 248 241 } 249 242 -
libcfa/src/concurrency/locks.cfa
rbae0d35 r53692b3 27 27 forall(L & | is_blocking_lock(L)) { 28 28 struct info_thread { 29 // used to put info_thread on a dl queue 30 inline dlink(info_thread(L));29 // used to put info_thread on a dl queue (aka sequence) 30 inline Seqable; 31 31 32 32 // waiting thread … … 42 42 bool signalled; 43 43 }; 44 P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) )45 44 46 45 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) { 46 ((Seqable &) this){}; 47 47 this.t = t; 48 48 this.info = info; … … 51 51 52 52 void ^?{}( info_thread(L) & this ) {} 53 54 info_thread(L) *& Back( info_thread(L) * this ) { 55 return (info_thread(L) *)Back( (Seqable *)this ); 56 } 57 58 info_thread(L) *& Next( info_thread(L) * this ) { 59 return (info_thread(L) *)Next( (Colable *)this ); 60 } 53 61 } 54 62 … … 77 85 // lock is held by some other thread 78 86 if ( owner != 0p && owner != thrd ) { 79 insert_last( blocked_threads, *thrd );87 addTail( blocked_threads, *thrd ); 80 88 wait_count++; 81 89 unlock( lock ); … … 116 124 117 125 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 118 $thread * t = & try_pop_front( blocked_threads );126 $thread * t = &dropHead( blocked_threads ); 119 127 owner = t; 120 128 recursion_count = ( t ? 1 : 0 ); … … 145 153 // lock held 146 154 if ( owner != 0p ) { 147 insert_last( blocked_threads, *t );155 addTail( blocked_threads, *t ); 148 156 wait_count++; 149 157 unlock( lock ); … … 198 206 // may still be called after a thread has been removed from the queue but 199 207 // before the alarm is unregistered 200 if ( (*info_thd)`isListed) { // is thread on queue208 if ( listed(info_thd) ) { // is thread on queue 201 209 info_thd->signalled = false; 202 210 // remove this thread O(1) 203 remove( *info_thd );211 remove( cond->blocked_threads, *info_thd ); 204 212 cond->count--; 205 213 if( info_thd->lock ) { … … 246 254 bool notify_one( condition_variable(L) & this ) with( this ) { 247 255 lock( lock __cfaabi_dbg_ctx2 ); 248 bool ret = ! blocked_threads`isEmpty;249 process_popped(this, try_pop_front( blocked_threads ));256 bool ret = !empty(blocked_threads); 257 process_popped(this, dropHead( blocked_threads )); 250 258 unlock( lock ); 251 259 return ret; … … 254 262 bool notify_all( condition_variable(L) & this ) with(this) { 255 263 lock( lock __cfaabi_dbg_ctx2 ); 256 bool ret = ! blocked_threads`isEmpty;257 while( ! blocked_threads`isEmpty) {258 process_popped(this, try_pop_front( blocked_threads ));264 bool ret = !empty(blocked_threads); 265 while( !empty(blocked_threads) ) { 266 process_popped(this, dropHead( blocked_threads )); 259 267 } 260 268 unlock( lock ); … … 263 271 264 272 uintptr_t front( condition_variable(L) & this ) with(this) { 265 return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;273 return empty(blocked_threads) ? NULL : head(blocked_threads).info; 266 274 } 267 275 268 276 bool empty( condition_variable(L) & this ) with(this) { 269 277 lock( lock __cfaabi_dbg_ctx2 ); 270 bool ret = blocked_threads`isEmpty;278 bool ret = empty(blocked_threads); 271 279 unlock( lock ); 272 280 return ret; … … 277 285 size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 278 286 // add info_thread to waiting queue 279 insert_last( blocked_threads, *i );287 addTail( blocked_threads, *i ); 280 288 count++; 281 289 size_t recursion_count = 0; -
libcfa/src/concurrency/locks.hfa
rbae0d35 r53692b3 21 21 #include "bits/weakso_locks.hfa" 22 22 #include "containers/queueLockFree.hfa" 23 #include "containers/list.hfa"24 23 25 24 #include "thread.hfa" … … 41 40 42 41 static inline bool P(Semaphore0nary & this, $thread * thrd) { 43 /* paranoid */ verify(! thrd`next);44 /* paranoid */ verify(!( &(*thrd)`next));42 /* paranoid */ verify(!(thrd->seqable.next)); 43 /* paranoid */ verify(!(thrd`next)); 45 44 46 45 push(this.queue, thrd); … … 251 250 252 251 //----------------------------------------------------------------------------- 253 // //info_thread254 // //the info thread is a wrapper around a thread used255 // //to store extra data for use in the condition variable252 // info_thread 253 // the info thread is a wrapper around a thread used 254 // to store extra data for use in the condition variable 256 255 forall(L & | is_blocking_lock(L)) { 257 256 struct info_thread; 258 257 259 // //for use by sequence260 //info_thread(L) *& Back( info_thread(L) * this );261 //info_thread(L) *& Next( info_thread(L) * this );258 // for use by sequence 259 info_thread(L) *& Back( info_thread(L) * this ); 260 info_thread(L) *& Next( info_thread(L) * this ); 262 261 } 263 262 … … 270 269 271 270 // List of blocked threads 272 dlist( info_thread(L) ) blocked_threads;271 Sequence( info_thread(L) ) blocked_threads; 273 272 274 273 // Count of current blocked threads 275 274 int count; 276 275 }; 277 278 276 279 277 void ?{}( condition_variable(L) & this );
Note: See TracChangeset
for help on using the changeset viewer.