* Fixed the TODO added by Ingo in r21957: locking the application didn't even make any
sense. Instead, we now lock its app_server connection only. The deadlock as exposed by starting Icon-O-Matic twice is now gone, at last. * Fixed the TODO added by Ingo in r21953: moved the thread/handler renaming code in a dedicated method _SetName() which is now called from _InitData() and SetTitle(); the "w>" is no longer lost. * Unlike the BeBook states, BMessageQueue::RemoveMessage() is indeed not supposed to delete the message it removes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21959 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -335,6 +335,7 @@ private:
|
|||||||
void _AdoptResize();
|
void _AdoptResize();
|
||||||
void _SetFocus(BView* focusView,
|
void _SetFocus(BView* focusView,
|
||||||
bool notifyIputServer = false);
|
bool notifyIputServer = false);
|
||||||
|
void _SetName(const char* title);
|
||||||
|
|
||||||
Shortcut* _FindShortcut(uint32 key, uint32 modifiers);
|
Shortcut* _FindShortcut(uint32 key, uint32 modifiers);
|
||||||
BView* _FindView(BView* view, BPoint point) const;
|
BView* _FindView(BView* view, BPoint point) const;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <input_globals.h>
|
#include <input_globals.h>
|
||||||
#include <AppMisc.h>
|
#include <AppMisc.h>
|
||||||
#include <ApplicationPrivate.h>
|
#include <ApplicationPrivate.h>
|
||||||
|
#include <AppServerLink.h>
|
||||||
#include <DirectMessageTarget.h>
|
#include <DirectMessageTarget.h>
|
||||||
#include <InputServerTypes.h>
|
#include <InputServerTypes.h>
|
||||||
#include <MenuPrivate.h>
|
#include <MenuPrivate.h>
|
||||||
@@ -279,8 +280,8 @@ BWindow::BWindow(BRect frame, const char* title, window_type type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BWindow::BWindow(BRect frame, const char* title, window_look look, window_feel feel,
|
BWindow::BWindow(BRect frame, const char* title, window_look look,
|
||||||
uint32 flags, uint32 workspace)
|
window_feel feel, uint32 flags, uint32 workspace)
|
||||||
: BLooper(title, B_DISPLAY_PRIORITY)
|
: BLooper(title, B_DISPLAY_PRIORITY)
|
||||||
{
|
{
|
||||||
_InitData(frame, title, look, feel, flags, workspace);
|
_InitData(frame, title, look, feel, flags, workspace);
|
||||||
@@ -852,7 +853,6 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
|
|||||||
height = nextHeight;
|
height = nextHeight;
|
||||||
|
|
||||||
MessageQueue()->RemoveMessage(pendingMessage);
|
MessageQueue()->RemoveMessage(pendingMessage);
|
||||||
// TODO: the BeBook says that MessageQueue::RemoveMessage() deletes the message!
|
|
||||||
delete pendingMessage;
|
delete pendingMessage;
|
||||||
// this deletes the first *additional* message
|
// this deletes the first *additional* message
|
||||||
// fCurrentMessage is safe
|
// fCurrentMessage is safe
|
||||||
@@ -1798,25 +1798,7 @@ BWindow::SetTitle(const char *title)
|
|||||||
free(fTitle);
|
free(fTitle);
|
||||||
fTitle = strdup(title);
|
fTitle = strdup(title);
|
||||||
|
|
||||||
// we will change BWindow's thread name to "w>window title"
|
_SetName(title);
|
||||||
|
|
||||||
char threadName[B_OS_NAME_LENGTH];
|
|
||||||
strcpy(threadName, "w>");
|
|
||||||
#ifdef __HAIKU__
|
|
||||||
strlcat(threadName, title, B_OS_NAME_LENGTH);
|
|
||||||
#else
|
|
||||||
int32 length = strlen(title);
|
|
||||||
length = min_c(length, B_OS_NAME_LENGTH - 3);
|
|
||||||
memcpy(threadName + 2, title, length);
|
|
||||||
threadName[length + 2] = '\0';
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// change the handler's name
|
|
||||||
SetName(threadName);
|
|
||||||
|
|
||||||
// if the message loop has been started...
|
|
||||||
if (Thread() >= B_OK)
|
|
||||||
rename_thread(Thread(), threadName);
|
|
||||||
|
|
||||||
// we notify the app_server so we can actually see the change
|
// we notify the app_server so we can actually see the change
|
||||||
if (Lock()) {
|
if (Lock()) {
|
||||||
@@ -2367,9 +2349,10 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
|
|||||||
|
|
||||||
if (title == NULL)
|
if (title == NULL)
|
||||||
title = "";
|
title = "";
|
||||||
// TODO: Where's da "w>"?
|
|
||||||
fTitle = strdup(title);
|
fTitle = strdup(title);
|
||||||
SetName(title);
|
|
||||||
|
_SetName(title);
|
||||||
|
|
||||||
fFeel = feel;
|
fFeel = feel;
|
||||||
fLook = look;
|
fLook = look;
|
||||||
@@ -2441,23 +2424,17 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
|
|||||||
|
|
||||||
STRACE(("BWindow::InitData(): contacting app_server...\n"));
|
STRACE(("BWindow::InitData(): contacting app_server...\n"));
|
||||||
|
|
||||||
// HERE we are in BApplication's thread, so for locking we use be_app variable
|
|
||||||
// we'll lock the be_app to be sure we're the only one writing at BApplication's server port
|
|
||||||
bool locked = false;
|
|
||||||
if (!be_app->IsLocked()) {
|
|
||||||
// TODO: This doesn't look good. If a window is created in the message handling
|
|
||||||
// code of another window, then the lock of that other window is already being
|
|
||||||
// held. So, if the application tries to lock that window from its message
|
|
||||||
// handling code, we get a beautiful deadlock. Start Icon-O-Matic, quit it, and
|
|
||||||
// start it a second time to see that in action.
|
|
||||||
be_app->Lock();
|
|
||||||
locked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// let app_server know that a window has been created.
|
// let app_server know that a window has been created.
|
||||||
fLink = new BPrivate::PortLink(
|
fLink = new BPrivate::PortLink(
|
||||||
BApplication::Private::ServerLink()->SenderPort(), receivePort);
|
BApplication::Private::ServerLink()->SenderPort(), receivePort);
|
||||||
|
|
||||||
|
{
|
||||||
|
BPrivate::AppServerLink lockLink;
|
||||||
|
// we're talking to the server application using our own
|
||||||
|
// communication channel (fLink) - we better make sure no one
|
||||||
|
// interferes by locking that channel (which AppServerLink does
|
||||||
|
// implicetly)
|
||||||
|
|
||||||
if (bitmapToken < 0) {
|
if (bitmapToken < 0) {
|
||||||
fLink->StartMessage(AS_CREATE_WINDOW);
|
fLink->StartMessage(AS_CREATE_WINDOW);
|
||||||
} else {
|
} else {
|
||||||
@@ -2496,9 +2473,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
|
|||||||
|
|
||||||
// Redirect our link to the new window connection
|
// Redirect our link to the new window connection
|
||||||
fLink->SetSenderPort(sendPort);
|
fLink->SetSenderPort(sendPort);
|
||||||
|
}
|
||||||
if (locked)
|
|
||||||
be_app->Unlock();
|
|
||||||
|
|
||||||
STRACE(("Server says that our send port is %ld\n", sendPort));
|
STRACE(("Server says that our send port is %ld\n", sendPort));
|
||||||
STRACE(("Window locked?: %s\n", IsLocked() ? "True" : "False"));
|
STRACE(("Window locked?: %s\n", IsLocked() ? "True" : "False"));
|
||||||
@@ -2507,6 +2482,35 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Rename the handler and its thread
|
||||||
|
void
|
||||||
|
BWindow::_SetName(const char *title)
|
||||||
|
{
|
||||||
|
if (title == NULL)
|
||||||
|
title = "";
|
||||||
|
|
||||||
|
// we will change BWindow's thread name to "w>window title"
|
||||||
|
|
||||||
|
char threadName[B_OS_NAME_LENGTH];
|
||||||
|
strcpy(threadName, "w>");
|
||||||
|
#ifdef __HAIKU__
|
||||||
|
strlcat(threadName, title, B_OS_NAME_LENGTH);
|
||||||
|
#else
|
||||||
|
int32 length = strlen(title);
|
||||||
|
length = min_c(length, B_OS_NAME_LENGTH - 3);
|
||||||
|
memcpy(threadName + 2, title, length);
|
||||||
|
threadName[length + 2] = '\0';
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// change the handler's name
|
||||||
|
SetName(threadName);
|
||||||
|
|
||||||
|
// if the message loop has been started...
|
||||||
|
if (Thread() >= B_OK)
|
||||||
|
rename_thread(Thread(), threadName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Reads all pending messages from the window port and put them into the queue.
|
//! Reads all pending messages from the window port and put them into the queue.
|
||||||
void
|
void
|
||||||
BWindow::_DequeueAll()
|
BWindow::_DequeueAll()
|
||||||
|
|||||||
Reference in New Issue
Block a user