Changeset 82f4063 for libcfa/src/concurrency/locks.cfa
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.