void WorkGangBarrierSync::enter() { MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag); if (should_reset()) { // The should_reset() was set and we are the first worker to enter // the sync barrier. We will zero the n_completed() count which // effectively resets the barrier. zero_completed(); set_should_reset(false); } inc_completed(); if (n_completed() == n_workers()) { // At this point we would like to reset the barrier to be ready in // case it is used again. However, we cannot set n_completed() to // 0, even after the notify_all(), given that some other workers // might still be waiting for n_completed() to become == // n_workers(). So, if we set n_completed() to 0, those workers // will get stuck (as they will wake up, see that n_completed() != // n_workers() and go back to sleep). Instead, we raise the // should_reset() flag and the barrier will be reset the first // time a worker enters it again. set_should_reset(true); monitor()->notify_all(); } else { while (n_completed() != n_workers()) { monitor()->wait(/* no_safepoint_check */ true); } } }
void WorkGangBarrierSync::enter() { MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag); inc_completed(); if (n_completed() == n_workers()) { monitor()->notify_all(); } else { while (n_completed() != n_workers()) { monitor()->wait(/* no_safepoint_check */ true); } } }