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