equal
deleted
inserted
replaced
198 ~MutexGangTaskDispatcher() { |
198 ~MutexGangTaskDispatcher() { |
199 delete _monitor; |
199 delete _monitor; |
200 } |
200 } |
201 |
201 |
202 void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) { |
202 void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) { |
203 MutexLocker ml(_monitor, Mutex::_no_safepoint_check_flag); |
203 MonitorLocker ml(_monitor, Mutex::_no_safepoint_check_flag); |
204 |
204 |
205 _task = task; |
205 _task = task; |
206 _num_workers = num_workers; |
206 _num_workers = num_workers; |
207 |
207 |
208 // Tell the workers to get to work. |
208 // Tell the workers to get to work. |
209 _monitor->notify_all(); |
209 _monitor->notify_all(); |
210 |
210 |
211 // Wait for them to finish. |
211 // Wait for them to finish. |
212 while (_finished < _num_workers) { |
212 while (_finished < _num_workers) { |
213 _monitor->wait_without_safepoint_check(); |
213 ml.wait(); |
214 } |
214 } |
215 |
215 |
216 _task = NULL; |
216 _task = NULL; |
217 _num_workers = 0; |
217 _num_workers = 0; |
218 _started = 0; |
218 _started = 0; |
365 _should_reset = false; |
365 _should_reset = false; |
366 _aborted = false; |
366 _aborted = false; |
367 } |
367 } |
368 |
368 |
369 bool WorkGangBarrierSync::enter() { |
369 bool WorkGangBarrierSync::enter() { |
370 MutexLocker x(monitor(), Mutex::_no_safepoint_check_flag); |
370 MonitorLocker ml(monitor(), Mutex::_no_safepoint_check_flag); |
371 if (should_reset()) { |
371 if (should_reset()) { |
372 // The should_reset() was set and we are the first worker to enter |
372 // The should_reset() was set and we are the first worker to enter |
373 // the sync barrier. We will zero the n_completed() count which |
373 // the sync barrier. We will zero the n_completed() count which |
374 // effectively resets the barrier. |
374 // effectively resets the barrier. |
375 zero_completed(); |
375 zero_completed(); |
385 // will get stuck (as they will wake up, see that n_completed() != |
385 // will get stuck (as they will wake up, see that n_completed() != |
386 // n_workers() and go back to sleep). Instead, we raise the |
386 // n_workers() and go back to sleep). Instead, we raise the |
387 // should_reset() flag and the barrier will be reset the first |
387 // should_reset() flag and the barrier will be reset the first |
388 // time a worker enters it again. |
388 // time a worker enters it again. |
389 set_should_reset(true); |
389 set_should_reset(true); |
390 monitor()->notify_all(); |
390 ml.notify_all(); |
391 } else { |
391 } else { |
392 while (n_completed() != n_workers() && !aborted()) { |
392 while (n_completed() != n_workers() && !aborted()) { |
393 monitor()->wait_without_safepoint_check(); |
393 ml.wait(); |
394 } |
394 } |
395 } |
395 } |
396 return !aborted(); |
396 return !aborted(); |
397 } |
397 } |
398 |
398 |