mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
Fixed use cases in code except CMS. Reviewed-by: rehn, dcubed
This commit is contained in:
parent
ed9eac2bb9
commit
ccb2e9d925
21 changed files with 91 additions and 101 deletions
|
@ -229,6 +229,7 @@ class MutexLocker: public StackObj {
|
|||
|
||||
// A MonitorLocker is like a MutexLocker above, except it allows
|
||||
// wait/notify as well which are delegated to the underlying Monitor.
|
||||
// It also disallows NULL.
|
||||
|
||||
class MonitorLocker: public MutexLocker {
|
||||
Mutex::SafepointCheckFlag _flag;
|
||||
|
@ -236,35 +237,31 @@ class MonitorLocker: public MutexLocker {
|
|||
MonitorLocker(Monitor* monitor, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
|
||||
MutexLocker(monitor, flag), _flag(flag) {
|
||||
// Superclass constructor did locking
|
||||
assert(_mutex != NULL, "NULL monitor not allowed");
|
||||
}
|
||||
|
||||
MonitorLocker(Monitor* monitor, Thread* thread, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
|
||||
MutexLocker(monitor, thread, flag), _flag(flag) {
|
||||
// Superclass constructor did locking
|
||||
assert(_mutex != NULL, "NULL monitor not allowed");
|
||||
}
|
||||
|
||||
bool wait(long timeout = 0,
|
||||
bool as_suspend_equivalent = !Mutex::_as_suspend_equivalent_flag) {
|
||||
if (_mutex != NULL) {
|
||||
if (_flag == Mutex::_safepoint_check_flag) {
|
||||
return _mutex->wait(timeout, as_suspend_equivalent);
|
||||
} else {
|
||||
return _mutex->wait_without_safepoint_check(timeout);
|
||||
}
|
||||
if (_flag == Mutex::_safepoint_check_flag) {
|
||||
return _mutex->wait(timeout, as_suspend_equivalent);
|
||||
} else {
|
||||
return _mutex->wait_without_safepoint_check(timeout);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void notify_all() {
|
||||
if (_mutex != NULL) {
|
||||
_mutex->notify_all();
|
||||
}
|
||||
_mutex->notify_all();
|
||||
}
|
||||
|
||||
void notify() {
|
||||
if (_mutex != NULL) {
|
||||
_mutex->notify();
|
||||
}
|
||||
_mutex->notify();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue