* 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
This commit is contained in:
Axel Dörfler
2007-01-25 17:08:16 +00:00
parent 6181d22fb0
commit ca9b91886d
3 changed files with 25 additions and 7 deletions
+2 -1
View File
@@ -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. * Distributed under the terms of the MIT License.
*/ */
#ifndef _MESSAGE_QUEUE_H #ifndef _MESSAGE_QUEUE_H
@@ -30,6 +30,7 @@ class BMessageQueue {
bool IsLocked() const; bool IsLocked() const;
BMessage *NextMessage(); BMessage *NextMessage();
bool IsNextMessage(const BMessage* message) const;
private: private:
// Reserved space in the vtable for future changes to BMessageQueue // Reserved space in the vtable for future changes to BMessageQueue
+10 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,7 +9,7 @@
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
*/ */
/** 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 @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 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);
}
} }
+13 -1
View File
@@ -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. * Distributed under the terms of the MIT License.
* *
* Authors: * 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! \brief This method is only here for R5 binary compatibility!
It should be dropped as soon as possible (it misses the const qualifier). It should be dropped as soon as possible (it misses the const qualifier).