Changes in / [089b1a9a:41cde266]
- Files:
-
- 1 deleted
- 3 edited
-
libcfa/src/concurrency/locks.cfa (modified) (8 diffs)
-
libcfa/src/concurrency/locks.hfa (modified) (4 diffs)
-
tests/locks.cfa (modified) (2 diffs)
-
tests/timeout_lock.cfa (deleted)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r089b1a9a r41cde266 17 17 this.t = t; 18 18 this.lock = 0p; 19 this.listed = false; 19 20 } 20 21 … … 24 25 this.info = info; 25 26 this.lock = 0p; 27 this.listed = false; 26 28 } 27 29 … … 34 36 info_thread(L) *& Next( info_thread(L) * this ) { 35 37 return (info_thread(L) *)Next( (Colable *)this ); 38 } 39 40 bool listed( info_thread(L) * this ) { 41 return Next( (Colable *)this ) != 0p; 36 42 } 37 43 } … … 188 194 // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin. 189 195 lock( cond->lock __cfaabi_dbg_ctx2 ); 190 if ( listed(i) ) { // is thread on queue191 i->signalled = false;196 197 if ( i->listed ) { // is thread on queue 192 198 cond->last_thread = i; // REMOVE THIS AFTER DEBUG 193 199 remove( cond->blocked_threads, *i ); //remove this thread O(1) … … 221 227 void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) { 222 228 if(&popped != 0p) { 223 popped. signalled = true;229 popped.listed = false; 224 230 count--; 225 231 if (popped.lock) { … … 260 266 addTail( blocked_threads, *i ); 261 267 count++; 268 i->listed = true; 262 269 size_t recursion_count = 0; 263 270 if (i->lock) { … … 301 308 } 302 309 303 boolwait( condition_variable(L) & this, Duration duration ) with(this) {310 void wait( condition_variable(L) & this, Duration duration ) with(this) { 304 311 info_thread( L ) i = { active_thread() }; 305 312 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 306 return i.signalled; 307 } 308 309 bool wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 313 } 314 315 void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 310 316 info_thread( L ) i = { active_thread(), info }; 311 317 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 312 return i.signalled; 313 } 314 315 bool wait( condition_variable(L) & this, Time time ) with(this) { 318 } 319 320 void wait( condition_variable(L) & this, Time time ) with(this) { 316 321 info_thread( L ) i = { active_thread() }; 317 322 queue_info_thread_timeout(this, i, time); 318 return i.signalled; 319 } 320 321 bool wait( condition_variable(L) & this, uintptr_t info, Time time ) with(this) { 323 } 324 325 void wait( condition_variable(L) & this, uintptr_t info, Time time ) with(this) { 322 326 info_thread( L ) i = { active_thread(), info }; 323 327 queue_info_thread_timeout(this, i, time); 324 return i.signalled;325 328 } 326 329 … … 337 340 } 338 341 339 boolwait( condition_variable(L) & this, L & l, Duration duration ) with(this) {342 void wait( condition_variable(L) & this, L & l, Duration duration ) with(this) { 340 343 info_thread(L) i = { active_thread() }; 341 344 i.lock = &l; 342 345 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 343 return i.signalled; 344 } 345 346 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { 346 } 347 348 void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { 347 349 info_thread(L) i = { active_thread(), info }; 348 350 i.lock = &l; 349 351 queue_info_thread_timeout(this, i, __kernel_get_time() + duration ); 350 return i.signalled; 351 } 352 353 bool wait( condition_variable(L) & this, L & l, Time time ) with(this) { 352 } 353 354 void wait( condition_variable(L) & this, L & l, Time time ) with(this) { 354 355 info_thread(L) i = { active_thread() }; 355 356 i.lock = &l; 356 357 queue_info_thread_timeout(this, i, time ); 357 return i.signalled; 358 } 359 360 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) { 358 } 359 360 void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) { 361 361 info_thread(L) i = { active_thread(), info }; 362 362 i.lock = &l; 363 363 queue_info_thread_timeout(this, i, time ); 364 return i.signalled; 365 } 366 } 364 } 365 } -
libcfa/src/concurrency/locks.hfa
r089b1a9a r41cde266 36 36 uintptr_t info; 37 37 L * lock; 38 bool signalled; // true when signalled and false when timeout wakes thread38 bool listed; // true if info_thread is on queue, false otherwise; 39 39 }; 40 40 … … 46 46 info_thread(L) *& Back( info_thread(L) * this ); 47 47 info_thread(L) *& Next( info_thread(L) * this ); 48 bool listed( info_thread(L) * this ); 48 49 } 49 50 … … 51 52 //// Blocking Locks 52 53 /////////////////////////////////////////////////////////////////// 54 55 // struct lock_thread { 56 // struct $thread * t; 57 // lock_thread * next; 58 // }; 59 60 // void ?{}( lock_thread & this, struct $thread * thd ); 61 // void ^?{}( lock_thread & this ); 62 63 // lock_thread *& get_next( lock_thread & ); 53 64 54 65 struct blocking_lock { … … 172 183 int counter( condition_variable(L) & this ); 173 184 185 // TODO: look into changing timout routines to return bool showing if signalled or woken by kernel 174 186 void wait( condition_variable(L) & this ); 175 187 void wait( condition_variable(L) & this, uintptr_t info ); 176 boolwait( condition_variable(L) & this, Duration duration );177 boolwait( condition_variable(L) & this, uintptr_t info, Duration duration );178 boolwait( condition_variable(L) & this, Time time );179 boolwait( condition_variable(L) & this, uintptr_t info, Time time );188 void wait( condition_variable(L) & this, Duration duration ); 189 void wait( condition_variable(L) & this, uintptr_t info, Duration duration ); 190 void wait( condition_variable(L) & this, Time time ); 191 void wait( condition_variable(L) & this, uintptr_t info, Time time ); 180 192 181 193 void wait( condition_variable(L) & this, L & l ); 182 194 void wait( condition_variable(L) & this, L & l, uintptr_t info ); 183 boolwait( condition_variable(L) & this, L & l, Duration duration );184 boolwait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );185 boolwait( condition_variable(L) & this, L & l, Time time );186 boolwait( condition_variable(L) & this, L & l, uintptr_t info, Time time );195 void wait( condition_variable(L) & this, L & l, Duration duration ); 196 void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ); 197 void wait( condition_variable(L) & this, L & l, Time time ); 198 void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ); 187 199 } -
tests/locks.cfa
r089b1a9a r41cde266 1 1 #include <stdio.h> 2 2 #include "locks.hfa" 3 4 #include "kernel_private.hfa" 5 #include <stdlib.h> 6 7 #include <kernel.hfa> 3 8 #include <stdlib.hfa> 4 9 #include <thread.hfa> … … 219 224 int main() { 220 225 processor p[2]; 221 wait( c_s, 1`ns );222 226 printf("Start Test 1: multi acquisition lock and condition variable single wait/notify\n"); 223 227 {
Note:
See TracChangeset
for help on using the changeset viewer.