Changeset 82f4063 for libcfa/src
- Timestamp:
- May 26, 2021, 10:38:19 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- bae0d35
- Parents:
- c65b930
- Location:
- libcfa/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/defs.hfa
rc65b930 r82f4063 31 31 #ifdef __cforall 32 32 #define __cfa_anonymous_object(x) inline struct x 33 #define __cfa_dlink(x) inline dlink(x) 33 34 #else 34 35 #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object 36 #define __cfa_dlink(x) struct { struct x * next; struct x * back; } __dlink_substitute 35 37 #endif 36 38 -
libcfa/src/bits/weakso_locks.hfa
rc65b930 r82f4063 21 21 #include "bits/sequence.hfa" 22 22 #include "bits/containers.hfa" 23 #include "containers/list.hfa" 23 24 24 25 struct $thread; … … 31 32 32 33 // List of blocked threads 33 Sequence( $thread ) blocked_threads;34 dlist( $thread ) blocked_threads; 34 35 35 36 // Count of current blocked threads -
libcfa/src/concurrency/invoke.h
rc65b930 r82f4063 20 20 21 21 #ifdef __cforall 22 #include "containers/list.hfa" 22 23 extern "C" { 23 24 #endif … … 196 197 } seqable; 197 198 199 // used to put threads on dlist data structure 200 __cfa_dlink($thread); 201 198 202 struct { 199 203 struct $thread * next; … … 207 211 #endif 208 212 }; 213 #ifdef __cforall 214 P9_EMBEDDED( $thread, dlink($thread) ) 215 #endif 209 216 // Wrapper for gdb 210 217 struct cfathread_thread_t { struct $thread debug; }; … … 236 243 237 244 static inline $thread *& Next( $thread * this ) __attribute__((const)) { 238 return this->seqable.next;245 return this->seqable.next; 239 246 } 240 247 -
libcfa/src/concurrency/locks.cfa
rc65b930 r82f4063 27 27 forall(L & | is_blocking_lock(L)) { 28 28 struct info_thread { 29 // used to put info_thread on a dl queue (aka sequence)30 inline Seqable;29 // used to put info_thread on a dl queue 30 inline dlink(info_thread(L)); 31 31 32 32 // waiting thread … … 42 42 bool signalled; 43 43 }; 44 P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) ) 44 45 45 46 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 }61 53 } 62 54 … … 85 77 // lock is held by some other thread 86 78 if ( owner != 0p && owner != thrd ) { 87 addTail( blocked_threads, *thrd );79 insert_last( blocked_threads, *thrd ); 88 80 wait_count++; 89 81 unlock( lock ); … … 124 116 125 117 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 126 $thread * t = & dropHead( blocked_threads );118 $thread * t = &try_pop_front( blocked_threads ); 127 119 owner = t; 128 120 recursion_count = ( t ? 1 : 0 ); … … 153 145 // lock held 154 146 if ( owner != 0p ) { 155 addTail( blocked_threads, *t );147 insert_last( blocked_threads, *t ); 156 148 wait_count++; 157 149 unlock( lock ); … … 206 198 // may still be called after a thread has been removed from the queue but 207 199 // before the alarm is unregistered 208 if ( listed(info_thd)) { // is thread on queue200 if ( (*info_thd)`isListed ) { // is thread on queue 209 201 info_thd->signalled = false; 210 202 // remove this thread O(1) 211 remove( cond->blocked_threads,*info_thd );203 remove( *info_thd ); 212 204 cond->count--; 213 205 if( info_thd->lock ) { … … 254 246 bool notify_one( condition_variable(L) & this ) with( this ) { 255 247 lock( lock __cfaabi_dbg_ctx2 ); 256 bool ret = ! empty(blocked_threads);257 process_popped(this, dropHead( blocked_threads ));248 bool ret = ! blocked_threads`isEmpty; 249 process_popped(this, try_pop_front( blocked_threads )); 258 250 unlock( lock ); 259 251 return ret; … … 262 254 bool notify_all( condition_variable(L) & this ) with(this) { 263 255 lock( lock __cfaabi_dbg_ctx2 ); 264 bool ret = ! empty(blocked_threads);265 while( ! empty(blocked_threads)) {266 process_popped(this, dropHead( blocked_threads ));256 bool ret = ! blocked_threads`isEmpty; 257 while( ! blocked_threads`isEmpty ) { 258 process_popped(this, try_pop_front( blocked_threads )); 267 259 } 268 260 unlock( lock ); … … 271 263 272 264 uintptr_t front( condition_variable(L) & this ) with(this) { 273 return empty(blocked_threads) ? NULL : head(blocked_threads).info;265 return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; 274 266 } 275 267 276 268 bool empty( condition_variable(L) & this ) with(this) { 277 269 lock( lock __cfaabi_dbg_ctx2 ); 278 bool ret = empty(blocked_threads);270 bool ret = blocked_threads`isEmpty; 279 271 unlock( lock ); 280 272 return ret; … … 285 277 size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 286 278 // add info_thread to waiting queue 287 addTail( blocked_threads, *i );279 insert_last( blocked_threads, *i ); 288 280 count++; 289 281 size_t recursion_count = 0; -
libcfa/src/concurrency/locks.hfa
rc65b930 r82f4063 21 21 #include "bits/weakso_locks.hfa" 22 22 #include "containers/queueLockFree.hfa" 23 #include "containers/list.hfa" 23 24 24 25 #include "thread.hfa" … … 40 41 41 42 static inline bool P(Semaphore0nary & this, $thread * thrd) { 42 /* paranoid */ verify(! (thrd->seqable.next));43 /* paranoid */ verify(!( thrd`next));43 /* paranoid */ verify(!thrd`next); 44 /* paranoid */ verify(!(&(*thrd)`next)); 44 45 45 46 push(this.queue, thrd); … … 250 251 251 252 //----------------------------------------------------------------------------- 252 // info_thread253 // the info thread is a wrapper around a thread used254 // to store extra data for use in the condition variable253 // // info_thread 254 // // the info thread is a wrapper around a thread used 255 // // to store extra data for use in the condition variable 255 256 forall(L & | is_blocking_lock(L)) { 256 257 struct info_thread; 257 258 258 // for use by sequence259 info_thread(L) *& Back( info_thread(L) * this );260 info_thread(L) *& Next( info_thread(L) * this );259 // // for use by sequence 260 // info_thread(L) *& Back( info_thread(L) * this ); 261 // info_thread(L) *& Next( info_thread(L) * this ); 261 262 } 262 263 … … 269 270 270 271 // List of blocked threads 271 Sequence( info_thread(L) ) blocked_threads;272 dlist( info_thread(L) ) blocked_threads; 272 273 273 274 // Count of current blocked threads 274 275 int count; 275 276 }; 277 276 278 277 279 void ?{}( condition_variable(L) & this );
Note: See TracChangeset
for help on using the changeset viewer.