1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Changed MessageBase::post() to return a bool to detect failure in the OS message queue (which can happen under stress on win32), and used this to avoid some messaging classes getting stuck.

This commit is contained in:
jules 2014-07-16 21:33:11 +01:00
parent 8baa07ac89
commit 7b8ab7b503
3 changed files with 22 additions and 7 deletions

View file

@ -61,7 +61,9 @@ AsyncUpdater::~AsyncUpdater()
void AsyncUpdater::triggerAsyncUpdate()
{
if (activeMessage->shouldDeliver.compareAndSetBool (1, 0))
activeMessage->post();
if (! activeMessage->post())
cancelPendingUpdate(); // if the message queue fails, this avoids getting
// trapped waiting for the message to arrive
}
void AsyncUpdater::cancelPendingUpdate() noexcept

View file

@ -66,12 +66,17 @@ void MessageManager::deleteInstance()
}
//==============================================================================
void MessageManager::MessageBase::post()
bool MessageManager::MessageBase::post()
{
MessageManager* const mm = MessageManager::instance;
if (mm == nullptr || mm->quitMessagePosted || ! postMessageToSystemQueue (this))
{
Ptr deleter (this); // (this will delete messages that were just created with a 0 ref count)
return false;
}
return true;
}
//==============================================================================
@ -158,9 +163,15 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* cons
jassert (! currentThreadHasLockedMessageManager());
const ReferenceCountedObjectPtr<AsyncFunctionCallback> message (new AsyncFunctionCallback (func, parameter));
message->post();
message->finished.wait();
return message->result;
if (message->post())
{
message->finished.wait();
return message->result;
}
jassertfalse; // the OS message queue failed to send the message!
return nullptr;
}
//==============================================================================
@ -275,7 +286,9 @@ bool MessageManagerLock::attemptLock (Thread* const threadToCheck, ThreadPoolJob
}
blockingMessage = new BlockingMessage();
blockingMessage->post();
if (! blockingMessage->post())
return false;
while (! blockingMessage->lockedEvent.wait (20))
{

View file

@ -170,7 +170,7 @@ public:
virtual ~MessageBase() {}
virtual void messageCallback() = 0;
void post();
bool post();
typedef ReferenceCountedObjectPtr<MessageBase> Ptr;