416 bool SubTasksDone::valid() { 417 return _tasks != NULL; 418 } 419 420 void SubTasksDone::clear() { 421 for (uint i = 0; i < _n_tasks; i++) { 422 _tasks[i] = 0; 423 } 424 _threads_completed = 0; 425 #ifdef ASSERT 426 _claimed = 0; 427 #endif 428 } 429 430 bool SubTasksDone::try_claim_task(uint t) { 431 assert(t < _n_tasks, "bad task id."); 432 uint old = _tasks[t]; 433 if (old == 0) { 434 old = Atomic::cmpxchg(1u, &_tasks[t], 0u); 435 } 436 assert(_tasks[t] == 1, "What else?"); 437 bool res = old == 0; 438 #ifdef ASSERT 439 if (res) { 440 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); 441 Atomic::inc(&_claimed); 442 } 443 #endif 444 return res; 445 } 446 447 void SubTasksDone::all_tasks_completed(uint n_threads) { 448 uint observed = _threads_completed; 449 uint old; 450 do { 451 old = observed; 452 observed = Atomic::cmpxchg(old+1, &_threads_completed, old); 453 } while (observed != old); 454 // If this was the last thread checking in, clear the tasks. 455 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); | 416 bool SubTasksDone::valid() { 417 return _tasks != NULL; 418 } 419 420 void SubTasksDone::clear() { 421 for (uint i = 0; i < _n_tasks; i++) { 422 _tasks[i] = 0; 423 } 424 _threads_completed = 0; 425 #ifdef ASSERT 426 _claimed = 0; 427 #endif 428 } 429 430 bool SubTasksDone::try_claim_task(uint t) { 431 assert(t < _n_tasks, "bad task id."); 432 uint old = _tasks[t]; 433 if (old == 0) { 434 old = Atomic::cmpxchg(1u, &_tasks[t], 0u); 435 } 436 437 DEBUG_ONLY(OrderAccess::fence()); // Prevent below load from floating up. 438 assert(_tasks[t] == 1, "What else?"); 439 bool res = old == 0; 440 #ifdef ASSERT 441 if (res) { 442 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); 443 Atomic::inc(&_claimed); 444 } 445 #endif 446 return res; 447 } 448 449 void SubTasksDone::all_tasks_completed(uint n_threads) { 450 uint observed = _threads_completed; 451 uint old; 452 do { 453 old = observed; 454 observed = Atomic::cmpxchg(old+1, &_threads_completed, old); 455 } while (observed != old); 456 // If this was the last thread checking in, clear the tasks. 457 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); |