* LockTarget[WithTimeout()]: Detect potential race condition where the looper
is deleted/recreated in between retrieval and lock. Report failure if so. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42073 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
4e1d68e994
commit
930a139d70
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2007, Haiku.
|
||||
* Copyright 2001-2011, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -212,7 +212,16 @@ BMessenger::LockTarget() const
|
||||
{
|
||||
BLooper *looper = NULL;
|
||||
Target(&looper);
|
||||
return looper && looper->Lock();
|
||||
if (looper && looper->Lock()) {
|
||||
if (looper->fMsgPort == fPort)
|
||||
return true;
|
||||
else {
|
||||
looper->Unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -237,6 +246,9 @@ BMessenger::LockTargetWithTimeout(bigtime_t timeout) const
|
||||
status_t error = looper ? B_OK : B_BAD_VALUE;
|
||||
if (error == B_OK)
|
||||
error = looper->LockWithTimeout(timeout);
|
||||
|
||||
if (error == B_OK && looper->fMsgPort != fPort)
|
||||
return B_BAD_PORT_ID;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user