BLocker: call debugger() when unlocking from another thread

BeOS did allow other threads than the owner to unlock a BLocker (the be
book says so). We did not, and silently ignored the unlock attempt in
this case, probably resulting in a deadlock of applications using the
feature.

Call debugger instead so:
* The problem is made visible for such apps
* The debugger call is continuable so the app can be run, still

Will help making a decision on what to do here (follow BeOS or change
behavior) and make a final decision for #6400.
This commit is contained in:
Adrien Destugues 2014-12-22 11:26:23 +01:00
parent a2b422eff9
commit 4227495829

View File

@ -108,12 +108,14 @@ BLocker::LockWithTimeout(bigtime_t timeout)
}
void
BLocker::Unlock()
{
// If the thread currently holds the lockdecrement
if (IsLocked()) {
// The Be Book explicitly allows any thread, not just the lock owner, to
// unlock. This is bad practise and Haiku should not allow it.
if (!IsLocked())
debugger("Trying to unlock from the wrong thread (#6400)");
// Decrement the number of outstanding locks this thread holds
// on this BLocker.
fRecursiveCount--;
@ -139,7 +141,6 @@ BLocker::Unlock()
}
}
}
}
thread_id
@ -217,10 +218,10 @@ BLocker::AcquireLock(bigtime_t timeout, status_t *error)
// Only try to acquire the lock if the thread doesn't already own it.
if (!IsLocked()) {
// Increment the benaphore count and test to see if it was already greater
// than 0. If it is greater than 0, then some thread already has the
// benaphore or the style is a semaphore. Either way, we need to acquire
// the semaphore in this case.
// Increment the benaphore count and test to see if it was already
// greater than 0. If it is greater than 0, then some thread already has
// the benaphore or the style is a semaphore. Either way, we need to
// acquire the semaphore in this case.
int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, 1);
if (oldBenaphoreCount > 0) {
do {