From 45db9a2073f50c9076e830d43fde3a34d3c41261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 31 Aug 2010 11:19:23 +0000 Subject: [PATCH] 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 --- src/servers/app/ServerWindow.cpp | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index ee4cb2e540..22326710bd 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -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