* 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:
Rene Gollent
2011-06-09 19:29:52 +00:00
parent 4e1d68e994
commit 930a139d70
+14 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. * Copyright 2001-2011, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -212,7 +212,16 @@ BMessenger::LockTarget() const
{ {
BLooper *looper = NULL; BLooper *looper = NULL;
Target(&looper); Target(&looper);
return looper && looper->Lock(); if (looper && looper->Lock()) {
if (looper->fMsgPort == fPort)
return true;
else {
looper->Unlock();
return false;
}
}
return false;
} }
@@ -238,6 +247,9 @@ BMessenger::LockTargetWithTimeout(bigtime_t timeout) const
if (error == B_OK) if (error == B_OK)
error = looper->LockWithTimeout(timeout); error = looper->LockWithTimeout(timeout);
if (error == B_OK && looper->fMsgPort != fPort)
return B_BAD_PORT_ID;
return error; return error;
} }