From f592fcef43a871aaa0e89bf306e14ec71500d7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 1 Jul 2008 15:47:56 +0000 Subject: [PATCH] stippi + bonefish: Fixed race conditions when a ServerApp or ServerWindow is created. The reply to the client that the object has been created successfully was sent in the thread creating it. Preempted at the wrong time (right after writing the message to the port) could lead to the object's thread using the link at the same time, which would screw up all subsequent communication via that link. This fixes the problem that mimeset would sometimes fail when building Haiku in Haiku (can't find the ticket). It probably also fixes #2331, and the bug that sometimes when a window is opened (Terminal, crash alert, shutdown window, etc.) it would come up with huge width/height and tiny other dimension (can't find the ticket). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26192 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ServerApp.cpp | 26 +++++--------------- src/servers/app/ServerApp.h | 1 - src/servers/app/ServerWindow.cpp | 42 ++++++++++++-------------------- src/servers/app/ServerWindow.h | 1 - 4 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 274e2962ca..ca0a09864f 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -205,26 +205,6 @@ ServerApp::InitCheck() } -/*! - \brief Starts the ServerApp monitoring for messages - \return false if the application couldn't start, true if everything went OK. -*/ -bool -ServerApp::Run() -{ - if (!MessageLooper::Run()) - return false; - - // Let's tell the client how to talk with us - fLink.StartMessage(B_OK); - fLink.Attach(fMessagePort); - fLink.Attach(fDesktop->SharedReadOnlyArea()); - fLink.Flush(); - - return true; -} - - /*! \brief This quits the application and deletes it. You're not supposed to call its destructor directly. @@ -340,6 +320,12 @@ ServerApp::_MessageLooper() { // Message-dispatching loop for the ServerApp + // First let's tell the client how to talk with us. + fLink.StartMessage(B_OK); + fLink.Attach(fMessagePort); + fLink.Attach(fDesktop->SharedReadOnlyArea()); + fLink.Flush(); + BPrivate::LinkReceiver &receiver = fLink.Receiver(); int32 code; diff --git a/src/servers/app/ServerApp.h b/src/servers/app/ServerApp.h index ec86f8fd08..8945ee0189 100644 --- a/src/servers/app/ServerApp.h +++ b/src/servers/app/ServerApp.h @@ -50,7 +50,6 @@ class ServerApp : public MessageLooper { status_t InitCheck(); void Quit(sem_id shutdownSemaphore = -1); - virtual bool Run(); virtual port_id MessagePort() const { return fMessagePort; } /*! diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 44417ba303..1adea2f396 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -297,32 +297,6 @@ ServerWindow::Init(BRect frame, window_look look, window_feel feel, } -bool -ServerWindow::Run() -{ - if (!MessageLooper::Run()) - return false; - - // Send a reply to our window - it is expecting fMessagePort - // port and some other info - - fLink.StartMessage(B_OK); - fLink.Attach(fMessagePort); - - int32 minWidth, maxWidth, minHeight, maxHeight; - fWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); - - fLink.Attach(fWindow->Frame()); - fLink.Attach((float)minWidth); - fLink.Attach((float)maxWidth); - fLink.Attach((float)minHeight); - fLink.Attach((float)maxHeight); - fLink.Flush(); - - return true; -} - - void ServerWindow::_PrepareQuit() { @@ -2844,6 +2818,22 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver &link) void ServerWindow::_MessageLooper() { + // Send a reply to our window - it is expecting fMessagePort + // port and some other info. + + fLink.StartMessage(B_OK); + fLink.Attach(fMessagePort); + + int32 minWidth, maxWidth, minHeight, maxHeight; + fWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + + fLink.Attach(fWindow->Frame()); + fLink.Attach((float)minWidth); + fLink.Attach((float)maxWidth); + fLink.Attach((float)minHeight); + fLink.Attach((float)maxHeight); + fLink.Flush(); + BPrivate::LinkReceiver& receiver = fLink.Receiver(); bool quitLoop = false; diff --git a/src/servers/app/ServerWindow.h b/src/servers/app/ServerWindow.h index 845d7252e6..d81f19da55 100644 --- a/src/servers/app/ServerWindow.h +++ b/src/servers/app/ServerWindow.h @@ -57,7 +57,6 @@ public: status_t Init(BRect frame, window_look look, window_feel feel, uint32 flags, uint32 workspace); - virtual bool Run(); virtual port_id MessagePort() const { return fMessagePort; } ::EventTarget& EventTarget() { return fEventTarget; }