227 } |
227 } |
228 }; |
228 }; |
229 |
229 |
230 // A MonitorLocker is like a MutexLocker above, except it allows |
230 // A MonitorLocker is like a MutexLocker above, except it allows |
231 // wait/notify as well which are delegated to the underlying Monitor. |
231 // wait/notify as well which are delegated to the underlying Monitor. |
|
232 // It also disallows NULL. |
232 |
233 |
233 class MonitorLocker: public MutexLocker { |
234 class MonitorLocker: public MutexLocker { |
234 Mutex::SafepointCheckFlag _flag; |
235 Mutex::SafepointCheckFlag _flag; |
235 public: |
236 public: |
236 MonitorLocker(Monitor* monitor, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) : |
237 MonitorLocker(Monitor* monitor, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) : |
237 MutexLocker(monitor, flag), _flag(flag) { |
238 MutexLocker(monitor, flag), _flag(flag) { |
238 // Superclass constructor did locking |
239 // Superclass constructor did locking |
|
240 assert(_mutex != NULL, "NULL monitor not allowed"); |
239 } |
241 } |
240 |
242 |
241 MonitorLocker(Monitor* monitor, Thread* thread, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) : |
243 MonitorLocker(Monitor* monitor, Thread* thread, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) : |
242 MutexLocker(monitor, thread, flag), _flag(flag) { |
244 MutexLocker(monitor, thread, flag), _flag(flag) { |
243 // Superclass constructor did locking |
245 // Superclass constructor did locking |
|
246 assert(_mutex != NULL, "NULL monitor not allowed"); |
244 } |
247 } |
245 |
248 |
246 bool wait(long timeout = 0, |
249 bool wait(long timeout = 0, |
247 bool as_suspend_equivalent = !Mutex::_as_suspend_equivalent_flag) { |
250 bool as_suspend_equivalent = !Mutex::_as_suspend_equivalent_flag) { |
248 if (_mutex != NULL) { |
251 if (_flag == Mutex::_safepoint_check_flag) { |
249 if (_flag == Mutex::_safepoint_check_flag) { |
252 return _mutex->wait(timeout, as_suspend_equivalent); |
250 return _mutex->wait(timeout, as_suspend_equivalent); |
253 } else { |
251 } else { |
254 return _mutex->wait_without_safepoint_check(timeout); |
252 return _mutex->wait_without_safepoint_check(timeout); |
|
253 } |
|
254 } |
255 } |
255 return false; |
256 return false; |
256 } |
257 } |
257 |
258 |
258 void notify_all() { |
259 void notify_all() { |
259 if (_mutex != NULL) { |
260 _mutex->notify_all(); |
260 _mutex->notify_all(); |
|
261 } |
|
262 } |
261 } |
263 |
262 |
264 void notify() { |
263 void notify() { |
265 if (_mutex != NULL) { |
264 _mutex->notify(); |
266 _mutex->notify(); |
|
267 } |
|
268 } |
265 } |
269 }; |
266 }; |
270 |
267 |
271 |
268 |
272 // A GCMutexLocker is usually initialized with a mutex that is |
269 // A GCMutexLocker is usually initialized with a mutex that is |