Browse Source

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.

tags/2021-05-28
jules 11 years ago
parent
commit
7b8ab7b503
3 changed files with 22 additions and 7 deletions
  1. +3
    -1
      modules/juce_events/broadcasters/juce_AsyncUpdater.cpp
  2. +18
    -5
      modules/juce_events/messages/juce_MessageManager.cpp
  3. +1
    -1
      modules/juce_events/messages/juce_MessageManager.h

+ 3
- 1
modules/juce_events/broadcasters/juce_AsyncUpdater.cpp 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


+ 18
- 5
modules/juce_events/messages/juce_MessageManager.cpp 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))
{


+ 1
- 1
modules/juce_events/messages/juce_MessageManager.h View File

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


Loading…
Cancel
Save