- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.cfa (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r43784ac r82f4063 16 16 17 17 #define __cforall_thread__ 18 #define _GNU_SOURCE19 18 20 19 #include "locks.hfa" … … 28 27 forall(L & | is_blocking_lock(L)) { 29 28 struct info_thread { 30 // used to put info_thread on a dl queue (aka sequence)31 inline Seqable;29 // used to put info_thread on a dl queue 30 inline dlink(info_thread(L)); 32 31 33 32 // waiting thread … … 43 42 bool signalled; 44 43 }; 44 P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) ) 45 45 46 46 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) { 47 ((Seqable &) this){};48 47 this.t = t; 49 48 this.info = info; … … 52 51 53 52 void ^?{}( info_thread(L) & this ) {} 54 55 info_thread(L) *& Back( info_thread(L) * this ) {56 return (info_thread(L) *)Back( (Seqable *)this );57 }58 59 info_thread(L) *& Next( info_thread(L) * this ) {60 return (info_thread(L) *)Next( (Colable *)this );61 }62 53 } 63 54 … … 86 77 // lock is held by some other thread 87 78 if ( owner != 0p && owner != thrd ) { 88 addTail( blocked_threads, *thrd );79 insert_last( blocked_threads, *thrd ); 89 80 wait_count++; 90 81 unlock( lock ); … … 125 116 126 117 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 127 $thread * t = & dropHead( blocked_threads );118 $thread * t = &try_pop_front( blocked_threads ); 128 119 owner = t; 129 120 recursion_count = ( t ? 1 : 0 ); … … 154 145 // lock held 155 146 if ( owner != 0p ) { 156 addTail( blocked_threads, *t );147 insert_last( blocked_threads, *t ); 157 148 wait_count++; 158 149 unlock( lock ); … … 207 198 // may still be called after a thread has been removed from the queue but 208 199 // before the alarm is unregistered 209 if ( listed(info_thd)) { // is thread on queue200 if ( (*info_thd)`isListed ) { // is thread on queue 210 201 info_thd->signalled = false; 211 202 // remove this thread O(1) 212 remove( cond->blocked_threads,*info_thd );203 remove( *info_thd ); 213 204 cond->count--; 214 205 if( info_thd->lock ) { … … 255 246 bool notify_one( condition_variable(L) & this ) with( this ) { 256 247 lock( lock __cfaabi_dbg_ctx2 ); 257 bool ret = ! empty(blocked_threads);258 process_popped(this, dropHead( blocked_threads ));248 bool ret = ! blocked_threads`isEmpty; 249 process_popped(this, try_pop_front( blocked_threads )); 259 250 unlock( lock ); 260 251 return ret; … … 263 254 bool notify_all( condition_variable(L) & this ) with(this) { 264 255 lock( lock __cfaabi_dbg_ctx2 ); 265 bool ret = ! empty(blocked_threads);266 while( ! empty(blocked_threads)) {267 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 )); 268 259 } 269 260 unlock( lock ); … … 272 263 273 264 uintptr_t front( condition_variable(L) & this ) with(this) { 274 return empty(blocked_threads) ? NULL : head(blocked_threads).info;265 return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; 275 266 } 276 267 277 268 bool empty( condition_variable(L) & this ) with(this) { 278 269 lock( lock __cfaabi_dbg_ctx2 ); 279 bool ret = empty(blocked_threads);270 bool ret = blocked_threads`isEmpty; 280 271 unlock( lock ); 281 272 return ret; … … 286 277 size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 287 278 // add info_thread to waiting queue 288 addTail( blocked_threads, *i );279 insert_last( blocked_threads, *i ); 289 280 count++; 290 281 size_t recursion_count = 0;
Note:
See TracChangeset
for help on using the changeset viewer.