From ca9b91886d763fed3bdc32530cd052ff0b7fef6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 25 Jan 2007 17:08:16 +0000 Subject: [PATCH] * Added a Dano extension to BMessageQueue: IsNextMessage(). * BLooper::AddMessage() is now using this method to determine wether or not to update its looper thread. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19956 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/app/MessageQueue.h | 3 ++- src/kits/app/Looper.cpp | 15 ++++++++++----- src/kits/app/MessageQueue.cpp | 14 +++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/headers/os/app/MessageQueue.h b/headers/os/app/MessageQueue.h index ef36ed3e72..eeea3eb23e 100644 --- a/headers/os/app/MessageQueue.h +++ b/headers/os/app/MessageQueue.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku, Inc. All Rights Reserved. + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _MESSAGE_QUEUE_H @@ -30,6 +30,7 @@ class BMessageQueue { bool IsLocked() const; BMessage *NextMessage(); + bool IsNextMessage(const BMessage* message) const; private: // Reserved space in the vtable for future changes to BMessageQueue diff --git a/src/kits/app/Looper.cpp b/src/kits/app/Looper.cpp index b4bffb58cb..4012fe6f41 100644 --- a/src/kits/app/Looper.cpp +++ b/src/kits/app/Looper.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku. + * Copyright 2001-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -9,7 +9,7 @@ * Axel Dörfler, axeld@pinc-software.de */ -/** BLooper class spawns a thread that runs a message loop. */ +/*! BLooper class spawns a thread that runs a message loop. */ /** @note Although I'm implementing "by the book" for now, I would like to @@ -1076,11 +1076,16 @@ BLooper::InitData(const char *name, int32 priority, int32 portCapacity) void -BLooper::AddMessage(BMessage* msg) +BLooper::AddMessage(BMessage* message) { - _AddMessagePriv(msg); + _AddMessagePriv(message); - // ToDo: if called from a different thread, we need to wake up the looper + // wakeup looper when being called from other threads if necessary + if (find_thread(NULL) != Thread() + && fQueue->IsNextMessage(message) && port_count(fMsgPort) <= 0) { + // there is currently no message waiting, and we need to wakeup the looper + write_port_etc(fMsgPort, 0, NULL, 0, B_RELATIVE_TIMEOUT, 0); + } } diff --git a/src/kits/app/MessageQueue.cpp b/src/kits/app/MessageQueue.cpp index 20cd219bc9..e9917adda8 100644 --- a/src/kits/app/MessageQueue.cpp +++ b/src/kits/app/MessageQueue.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku, Inc. All Rights Reserved. + * Copyright 2001-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -262,6 +262,18 @@ BMessageQueue::NextMessage() } +/*! + \brief Checks wether or not the specified \a message is the message + you would get when calling NextMessage(). +*/ +bool +BMessageQueue::IsNextMessage(const BMessage* message) const +{ + BAutolock _(fLock); + return fHead == message; +} + + /*! \brief This method is only here for R5 binary compatibility! It should be dropped as soon as possible (it misses the const qualifier).