src/hotspot/share/gc/shared/workgroup.cpp
changeset 51598 c88019b32bc4
parent 51546 b9f6a4427da9
child 52302 912b79d983d9
equal deleted inserted replaced
51597:4c78f4fd8370 51598:c88019b32bc4
   427 #ifdef ASSERT
   427 #ifdef ASSERT
   428   _claimed = 0;
   428   _claimed = 0;
   429 #endif
   429 #endif
   430 }
   430 }
   431 
   431 
   432 bool SubTasksDone::is_task_claimed(uint t) {
   432 bool SubTasksDone::try_claim_task(uint t) {
   433   assert(t < _n_tasks, "bad task id.");
   433   assert(t < _n_tasks, "bad task id.");
   434   uint old = _tasks[t];
   434   uint old = _tasks[t];
   435   if (old == 0) {
   435   if (old == 0) {
   436     old = Atomic::cmpxchg(1u, &_tasks[t], 0u);
   436     old = Atomic::cmpxchg(1u, &_tasks[t], 0u);
   437   }
   437   }
   438   assert(_tasks[t] == 1, "What else?");
   438   assert(_tasks[t] == 1, "What else?");
   439   bool res = old != 0;
   439   bool res = old == 0;
   440 #ifdef ASSERT
   440 #ifdef ASSERT
   441   if (!res) {
   441   if (res) {
   442     assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?");
   442     assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?");
   443     Atomic::inc(&_claimed);
   443     Atomic::inc(&_claimed);
   444   }
   444   }
   445 #endif
   445 #endif
   446   return res;
   446   return res;
   474 
   474 
   475 bool SequentialSubTasksDone::valid() {
   475 bool SequentialSubTasksDone::valid() {
   476   return _n_threads > 0;
   476   return _n_threads > 0;
   477 }
   477 }
   478 
   478 
   479 bool SequentialSubTasksDone::is_task_claimed(uint& t) {
   479 bool SequentialSubTasksDone::try_claim_task(uint& t) {
   480   t = _n_claimed;
   480   t = _n_claimed;
   481   while (t < _n_tasks) {
   481   while (t < _n_tasks) {
   482     uint res = Atomic::cmpxchg(t+1, &_n_claimed, t);
   482     uint res = Atomic::cmpxchg(t+1, &_n_claimed, t);
   483     if (res == t) {
   483     if (res == t) {
   484       return false;
   484       return true;
   485     }
   485     }
   486     t = res;
   486     t = res;
   487   }
   487   }
   488   return true;
   488   return false;
   489 }
   489 }
   490 
   490 
   491 bool SequentialSubTasksDone::all_tasks_completed() {
   491 bool SequentialSubTasksDone::all_tasks_completed() {
   492   uint complete = _n_completed;
   492   uint complete = _n_completed;
   493   while (true) {
   493   while (true) {