equal
deleted
inserted
replaced
424 |
424 |
425 bool SubTasksDone::try_claim_task(uint t) { |
425 bool SubTasksDone::try_claim_task(uint t) { |
426 assert(t < _n_tasks, "bad task id."); |
426 assert(t < _n_tasks, "bad task id."); |
427 uint old = _tasks[t]; |
427 uint old = _tasks[t]; |
428 if (old == 0) { |
428 if (old == 0) { |
429 old = Atomic::cmpxchg(1u, &_tasks[t], 0u); |
429 old = Atomic::cmpxchg(&_tasks[t], 0u, 1u); |
430 } |
430 } |
431 bool res = old == 0; |
431 bool res = old == 0; |
432 #ifdef ASSERT |
432 #ifdef ASSERT |
433 if (res) { |
433 if (res) { |
434 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); |
434 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); |
441 void SubTasksDone::all_tasks_completed(uint n_threads) { |
441 void SubTasksDone::all_tasks_completed(uint n_threads) { |
442 uint observed = _threads_completed; |
442 uint observed = _threads_completed; |
443 uint old; |
443 uint old; |
444 do { |
444 do { |
445 old = observed; |
445 old = observed; |
446 observed = Atomic::cmpxchg(old+1, &_threads_completed, old); |
446 observed = Atomic::cmpxchg(&_threads_completed, old, old+1); |
447 } while (observed != old); |
447 } while (observed != old); |
448 // If this was the last thread checking in, clear the tasks. |
448 // If this was the last thread checking in, clear the tasks. |
449 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); |
449 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); |
450 if (observed + 1 == adjusted_thread_count) { |
450 if (observed + 1 == adjusted_thread_count) { |
451 clear(); |
451 clear(); |
469 } |
469 } |
470 |
470 |
471 bool SequentialSubTasksDone::try_claim_task(uint& t) { |
471 bool SequentialSubTasksDone::try_claim_task(uint& t) { |
472 t = _n_claimed; |
472 t = _n_claimed; |
473 while (t < _n_tasks) { |
473 while (t < _n_tasks) { |
474 uint res = Atomic::cmpxchg(t+1, &_n_claimed, t); |
474 uint res = Atomic::cmpxchg(&_n_claimed, t, t+1); |
475 if (res == t) { |
475 if (res == t) { |
476 return true; |
476 return true; |
477 } |
477 } |
478 t = res; |
478 t = res; |
479 } |
479 } |
481 } |
481 } |
482 |
482 |
483 bool SequentialSubTasksDone::all_tasks_completed() { |
483 bool SequentialSubTasksDone::all_tasks_completed() { |
484 uint complete = _n_completed; |
484 uint complete = _n_completed; |
485 while (true) { |
485 while (true) { |
486 uint res = Atomic::cmpxchg(complete+1, &_n_completed, complete); |
486 uint res = Atomic::cmpxchg(&_n_completed, complete, complete+1); |
487 if (res == complete) { |
487 if (res == complete) { |
488 break; |
488 break; |
489 } |
489 } |
490 complete = res; |
490 complete = res; |
491 } |
491 } |