The fWindowLock is now responsible for all window activities - no need to sometimes

lock the Desktop itself, and sometimes not - that also fixes some potential deadlock
situations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15463 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-12-10 13:47:13 +00:00
parent e76d86d5dd
commit a447191925
2 changed files with 30 additions and 24 deletions
+28 -22
View File
@@ -144,7 +144,8 @@ KeyboardFilter::Filter(BMessage* message, EventTarget** _target,
bigtime_t now = system_time(); bigtime_t now = system_time();
fDesktop->ReadLockWindows(); if (!fDesktop->ReadLockWindows())
return B_DISPATCH_MESSAGE;
EventTarget* focus = NULL; EventTarget* focus = NULL;
if (fDesktop->FocusWindow() != NULL) if (fDesktop->FocusWindow() != NULL)
@@ -195,7 +196,8 @@ MouseFilter::Filter(BMessage* message, EventTarget** _target, int32* _viewToken)
if (message->FindPoint("where", &where) != B_OK) if (message->FindPoint("where", &where) != B_OK)
return B_DISPATCH_MESSAGE; return B_DISPATCH_MESSAGE;
fDesktop->WriteLockWindows(); if (!fDesktop->WriteLockWindows())
return B_DISPATCH_MESSAGE;
WindowLayer* window = fDesktop->MouseEventWindow(); WindowLayer* window = fDesktop->MouseEventWindow();
if (window == NULL) if (window == NULL)
@@ -572,13 +574,13 @@ Desktop::UpdateWorkspaces()
void void
Desktop::SetWorkspace(int32 index) Desktop::SetWorkspace(int32 index)
{ {
BAutolock _(this); WriteLockWindows();
DesktopSettings settings(this); DesktopSettings settings(this);
if (index < 0 || index >= settings.WorkspacesCount() || index == fCurrentWorkspace) if (index < 0 || index >= settings.WorkspacesCount() || index == fCurrentWorkspace) {
WriteUnlockWindows();
return; return;
}
WriteLockWindows();
int32 previousIndex = fCurrentWorkspace; int32 previousIndex = fCurrentWorkspace;
@@ -679,10 +681,8 @@ Desktop::SetWorkspace(int32 index)
SetFocusWindow(FrontWindow()); SetFocusWindow(FrontWindow());
_WindowChanged(NULL); _WindowChanged(NULL);
MarkDirty(dirty); MarkDirty(dirty);
//_WindowsChanged();
WriteUnlockWindows(); WriteUnlockWindows();
} }
@@ -693,10 +693,6 @@ Desktop::ScreenChanged(Screen* screen)
// TODO: confirm that everywhere this is used, // TODO: confirm that everywhere this is used,
// the Window WriteLock is held // the Window WriteLock is held
// TODO: can this be removed? I would think it can.
// In fact, this lock should nowhere be used anymore, no?
// BAutolock locker(this);
// the entire screen is dirty, because we're actually // the entire screen is dirty, because we're actually
// operating on an all new buffer in memory // operating on an all new buffer in memory
BRegion dirty(screen->Frame()); BRegion dirty(screen->Frame());
@@ -1360,19 +1356,20 @@ Desktop::_ChangeWindowWorkspaces(WindowLayer* window, uint32 oldWorkspaces,
void void
Desktop::SetWindowWorkspaces(WindowLayer* window, uint32 workspaces) Desktop::SetWindowWorkspaces(WindowLayer* window, uint32 workspaces)
{ {
BAutolock _(this); WriteLockWindows();
if (window->IsNormal() && workspaces == B_CURRENT_WORKSPACE) if (window->IsNormal() && workspaces == B_CURRENT_WORKSPACE)
workspaces = workspace_to_workspaces(CurrentWorkspace()); workspaces = workspace_to_workspaces(CurrentWorkspace());
_ChangeWindowWorkspaces(window, window->Workspaces(), workspaces); _ChangeWindowWorkspaces(window, window->Workspaces(), workspaces);
WriteUnlockWindows();
} }
void void
Desktop::AddWindow(WindowLayer *window) Desktop::AddWindow(WindowLayer *window)
{ {
BAutolock _(this); WriteLockWindows();
fAllWindows.AddWindow(window); fAllWindows.AddWindow(window);
if (!window->IsNormal()) if (!window->IsNormal())
@@ -1387,13 +1384,14 @@ Desktop::AddWindow(WindowLayer *window)
} }
_ChangeWindowWorkspaces(window, 0, window->Workspaces()); _ChangeWindowWorkspaces(window, 0, window->Workspaces());
WriteUnlockWindows();
} }
void void
Desktop::RemoveWindow(WindowLayer *window) Desktop::RemoveWindow(WindowLayer *window)
{ {
BAutolock _(this); WriteLockWindows();
if (!window->IsHidden()) if (!window->IsHidden())
HideWindow(window); HideWindow(window);
@@ -1403,6 +1401,7 @@ Desktop::RemoveWindow(WindowLayer *window)
fSubsetWindows.RemoveWindow(window); fSubsetWindows.RemoveWindow(window);
_ChangeWindowWorkspaces(window, window->Workspaces(), 0); _ChangeWindowWorkspaces(window, window->Workspaces(), 0);
WriteUnlockWindows();
// make sure this window won't get any events anymore // make sure this window won't get any events anymore
@@ -1460,7 +1459,7 @@ Desktop::SetWindowFeel(WindowLayer *window, window_feel newFeel)
if (window->Feel() == newFeel) if (window->Feel() == newFeel)
return; return;
BAutolock _(this); WriteLockWindows();
bool wasNormal = window->IsNormal(); bool wasNormal = window->IsNormal();
@@ -1510,6 +1509,8 @@ Desktop::SetWindowFeel(WindowLayer *window, window_feel newFeel)
if (window == FocusWindow() && !window->IsVisible()) if (window == FocusWindow() && !window->IsVisible())
SetFocusWindow(FrontWindow()); SetFocusWindow(FrontWindow());
WriteUnlockWindows();
} }
@@ -1560,11 +1561,13 @@ Desktop::SetWindowTitle(WindowLayer *window, const char* title)
} }
/*!
Returns the window under the mouse cursor.
You need to have the window write lock acquired when calling this method.
*/
WindowLayer* WindowLayer*
Desktop::WindowAt(BPoint where) Desktop::WindowAt(BPoint where)
{ {
// TODO: BAutolock locker(this); ?!?
for (WindowLayer* window = _CurrentWindows().LastWindow(); window; for (WindowLayer* window = _CurrentWindows().LastWindow(); window;
window = window->PreviousWindow(fCurrentWorkspace)) { window = window->PreviousWindow(fCurrentWorkspace)) {
if (window->VisibleRegion().Contains(where)) if (window->VisibleRegion().Contains(where))
@@ -1585,15 +1588,18 @@ Desktop::SetMouseEventWindow(WindowLayer* window)
WindowLayer * WindowLayer *
Desktop::FindWindowLayerByClientToken(int32 token, team_id teamID) Desktop::FindWindowLayerByClientToken(int32 token, team_id teamID)
{ {
BAutolock locker(this); ReadLockWindows();
for (WindowLayer *window = fAllWindows.FirstWindow(); window != NULL; for (WindowLayer *window = fAllWindows.FirstWindow(); window != NULL;
window = window->NextWindow(kAllWindowList)) { window = window->NextWindow(kAllWindowList)) {
if (window->ServerWindow()->ClientToken() == token if (window->ServerWindow()->ClientToken() == token
&& window->ServerWindow()->ClientTeam() == teamID) && window->ServerWindow()->ClientTeam() == teamID) {
ReadUnlockWindows();
return window; return window;
}
} }
ReadUnlockWindows();
return NULL; return NULL;
} }
@@ -1601,7 +1607,7 @@ Desktop::FindWindowLayerByClientToken(int32 token, team_id teamID)
void void
Desktop::WriteWindowList(team_id team, BPrivate::LinkSender& sender) Desktop::WriteWindowList(team_id team, BPrivate::LinkSender& sender)
{ {
BAutolock locker(this); BAutolock locker(fWindowLock);
// compute the number of windows // compute the number of windows
@@ -1633,7 +1639,7 @@ Desktop::WriteWindowList(team_id team, BPrivate::LinkSender& sender)
void void
Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender) Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender)
{ {
BAutolock locker(this); BAutolock locker(fWindowLock);
BAutolock tokenLocker(BPrivate::gDefaultTokens); BAutolock tokenLocker(BPrivate::gDefaultTokens);
::ServerWindow* window; ::ServerWindow* window;
+2 -2
View File
@@ -72,14 +72,14 @@ Workspace::Workspace(Desktop& desktop, int32 index)
fDesktop(desktop), fDesktop(desktop),
fCurrentWorkspace(index == desktop.CurrentWorkspace()) fCurrentWorkspace(index == desktop.CurrentWorkspace())
{ {
fDesktop.Lock(); fDesktop.ReadLockWindows();
RewindWindows(); RewindWindows();
} }
Workspace::~Workspace() Workspace::~Workspace()
{ {
fDesktop.Unlock(); fDesktop.ReadUnlockWindows();
} }