Made the logic behind the locking in the outer and inner

message loop more clear, both in the code and also via
comments. I get the occasional drop into the debugger
because MultiLocker says the Readlock has been acquired
twice. I don't see how it is possible from the code and
it could be another bug in the MultiLocker debugging
facilities, but the code should be clearer now anyway.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38477 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-08-31 11:19:23 +00:00
parent cb2fa7e665
commit 45db9a2073

View File

@ -3379,8 +3379,7 @@ ServerWindow::_MessageLooper()
int32 messagesProcessed = 0;
bigtime_t processingStart = system_time();
bool lockedDesktop = false;
bool needsAllWindowsLocked = false;
bool lockedDesktopSingleWindow = false;
while (true) {
if (code == AS_DELETE_WINDOW || code == kMsgQuitLooper) {
@ -3393,7 +3392,7 @@ ServerWindow::_MessageLooper()
fLink.Flush();
}
if (lockedDesktop)
if (lockedDesktopSingleWindow)
fDesktop->UnlockSingleWindow();
quitLoop = true;
@ -3404,21 +3403,24 @@ ServerWindow::_MessageLooper()
break;
}
needsAllWindowsLocked = _MessageNeedsAllWindowsLocked(code);
if (!lockedDesktop && !needsAllWindowsLocked) {
// only lock it once
fDesktop->LockSingleWindow();
lockedDesktop = true;
} else if (lockedDesktop && !needsAllWindowsLocked) {
// nothing to do
} else if (needsAllWindowsLocked) {
if (lockedDesktop) {
// unlock single before locking all
// Acquire the appropriate lock
bool needsAllWindowsLocked = _MessageNeedsAllWindowsLocked(code);
if (needsAllWindowsLocked) {
// We may already still hold the read-lock from the previous
// inner-loop iteration.
if (lockedDesktopSingleWindow) {
fDesktop->UnlockSingleWindow();
lockedDesktop = false;
lockedDesktopSingleWindow = false;
}
fDesktop->LockAllWindows();
} else {
// We never keep the write-lock across inner-loop iterations,
// so there is nothing else to do besides read-locking unless
// we already have the read-lock from the previous iteration.
if (!lockedDesktopSingleWindow) {
fDesktop->LockSingleWindow();
lockedDesktopSingleWindow = true;
}
}
if (atomic_and(&fRedrawRequested, 0) != 0) {
@ -3465,7 +3467,7 @@ ServerWindow::_MessageLooper()
// Desktop locked), but don't hold the lock longer than 10 ms
if (!receiver.HasMessages() || ++messagesProcessed > 70
|| system_time() - processingStart > 10000) {
if (lockedDesktop)
if (lockedDesktopSingleWindow)
fDesktop->UnlockSingleWindow();
break;
}
@ -3475,7 +3477,7 @@ ServerWindow::_MessageLooper()
if (status != B_OK) {
// that shouldn't happen, it's our port
printf("Someone deleted our message port!\n");
if (lockedDesktop)
if (lockedDesktopSingleWindow)
fDesktop->UnlockSingleWindow();
// try to let our client die happily