hrev43821 adds 1 changeset to branch 'master' old head: d41ac61f731647ec6a45d69396d0d7bb7f52ba5c new head: a0e9f8e205d081b64afe5ef9f30230ed9c16d011 ---------------------------------------------------------------------------- a0e9f8e: Fixed wrong assert and locking when using Workspace objects. * The assert in the Workspace constructor was definitely for the wrong lock. One should be holding the all window lock either in read or write mode. The Desktop message loop lock should be unrelated. * Added boolean to the constructor which controls the assert. * Added documentation to Workspace class, since it's not at all obvious how this is intended to be used. * Fixed ServerApp to lock the Desktop correctly when using Workspace desktop colors. [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev43821 Commit: a0e9f8e205d081b64afe5ef9f30230ed9c16d011 URL: http://cgit.haiku-os.org/haiku/commit/?id=a0e9f8e Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Mar 4 13:28:41 2012 UTC ---------------------------------------------------------------------------- 4 files changed, 17 insertions(+), 10 deletions(-) src/servers/app/ServerApp.cpp | 10 +++++----- src/servers/app/Workspace.cpp | 5 +++-- src/servers/app/Workspace.h | 10 ++++++++-- src/servers/app/WorkspacesView.cpp | 2 +- ---------------------------------------------------------------------------- diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 16d3cd0..65e4bfa 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -2754,17 +2754,17 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read<uint32>(&index); fLink.StartMessage(B_OK); - fDesktop->Lock(); + fDesktop->LockSingleWindow(); // we're nice to our children (and also take the default case // into account which asks for the current workspace) if (index >= (uint32)kMaxWorkspaces) index = fDesktop->CurrentWorkspace(); - Workspace workspace(*fDesktop, index); + Workspace workspace(*fDesktop, index, true); fLink.Attach<rgb_color>(workspace.Color()); - fDesktop->Unlock(); + fDesktop->UnlockSingleWindow(); fLink.Flush(); break; } @@ -2782,7 +2782,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) if (link.Read<bool>(&makeDefault) != B_OK) break; - fDesktop->Lock(); + fDesktop->LockAllWindows(); // we're nice to our children (and also take the default case // into account which asks for the current workspace) @@ -2792,7 +2792,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) Workspace workspace(*fDesktop, index); workspace.SetColor(color, makeDefault); - fDesktop->Unlock(); + fDesktop->UnlockAllWindows(); break; } diff --git a/src/servers/app/Workspace.cpp b/src/servers/app/Workspace.cpp index b2aa0ff..1b890dd 100644 --- a/src/servers/app/Workspace.cpp +++ b/src/servers/app/Workspace.cpp @@ -79,13 +79,14 @@ Workspace::Private::_SetDefaults() // #pragma mark - -Workspace::Workspace(Desktop& desktop, int32 index) +Workspace::Workspace(Desktop& desktop, int32 index, bool readOnly) : fWorkspace(desktop.WorkspaceAt(index)), fDesktop(desktop), fCurrentWorkspace(index == desktop.CurrentWorkspace()) { - ASSERT(desktop.IsLocked()); + ASSERT(desktop.WindowLocker().IsWriteLocked() + || ( readOnly && desktop.WindowLocker().IsReadLocked())); RewindWindows(); } diff --git a/src/servers/app/Workspace.h b/src/servers/app/Workspace.h index 4921133..7e0bfe9 100644 --- a/src/servers/app/Workspace.h +++ b/src/servers/app/Workspace.h @@ -15,10 +15,16 @@ class Desktop; class Window; - +/*! +Workspace objects are intended to be short-lived. You create them while +already holding a lock to the Desktop read-write lock and then you can use them +to query information, and then you destroy them again, for example by letting +them go out of scope. +*/ class Workspace { public: - Workspace(Desktop& desktop, int32 index); + Workspace(Desktop& desktop, int32 index, + bool readOnly = false); ~Workspace(); const rgb_color& Color() const; diff --git a/src/servers/app/WorkspacesView.cpp b/src/servers/app/WorkspacesView.cpp index c20e12c..a475aad 100644 --- a/src/servers/app/WorkspacesView.cpp +++ b/src/servers/app/WorkspacesView.cpp @@ -277,7 +277,7 @@ WorkspacesView::_DrawWorkspace(DrawingEngine* drawingEngine, { BRect rect = _WorkspaceAt(index); - Workspace workspace(*Window()->Desktop(), index); + Workspace workspace(*Window()->Desktop(), index, true); bool workspaceActive = workspace.IsCurrent(); if (workspaceActive) { // draw active frame