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

Modernised some old code.

This commit is contained in:
Julian Storer 2010-02-20 15:27:48 +00:00
parent 5c027142f4
commit 39b583fe1e
27 changed files with 966 additions and 1426 deletions

View file

@ -229,28 +229,27 @@ bool MessageManager::currentThreadHasLockedMessageManager() const throw()
accessed from another thread inside a MM lock, you're screwed. (this is exactly what happens
in Cocoa).
*/
class SharedLockingEvents : public ReferenceCountedObject
class MessageManagerLock::SharedEvents : public ReferenceCountedObject
{
public:
SharedLockingEvents() throw() {}
~SharedLockingEvents() {}
SharedEvents() {}
~SharedEvents() {}
/* This class just holds a couple of events to communicate between the MMLockMessage
/* This class just holds a couple of events to communicate between the BlockingMessage
and the MessageManagerLock. Because both of these objects may be deleted at any time,
this shared data must be kept in a separate, ref-counted container. */
WaitableEvent lockedEvent, releaseEvent;
private:
SharedEvents (const SharedEvents&);
SharedEvents& operator= (const SharedEvents&);
};
class MMLockMessage : public CallbackMessage
class MessageManagerLock::BlockingMessage : public CallbackMessage
{
public:
MMLockMessage (SharedLockingEvents* const events_) throw()
: events (events_)
{}
~MMLockMessage() throw() {}
ReferenceCountedObjectPtr <SharedLockingEvents> events;
BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
~BlockingMessage() throw() {}
void messageCallback()
{
@ -260,21 +259,24 @@ public:
juce_UseDebuggingNewOperator
MMLockMessage (const MMLockMessage&);
const MMLockMessage& operator= (const MMLockMessage&);
private:
ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
BlockingMessage (const BlockingMessage&);
BlockingMessage& operator= (const BlockingMessage&);
};
//==============================================================================
MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
: locked (false),
needsUnlocking (false)
: sharedEvents (0),
locked (false)
{
init (threadToCheck, 0);
}
MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
: locked (false),
needsUnlocking (false)
: sharedEvents (0),
locked (false)
{
init (0, jobToCheckForExitSignal);
}
@ -305,19 +307,19 @@ void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const
}
}
SharedLockingEvents* const events = new SharedLockingEvents();
sharedEvents = events;
events->incReferenceCount();
sharedEvents = new SharedEvents();
sharedEvents->incReferenceCount();
(new MMLockMessage (events))->post();
(new BlockingMessage (sharedEvents))->post();
while (! events->lockedEvent.wait (50))
while (! sharedEvents->lockedEvent.wait (50))
{
if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
|| (job != 0 && job->shouldExit()))
{
events->releaseEvent.signal();
events->decReferenceCount();
sharedEvents->releaseEvent.signal();
sharedEvents->decReferenceCount();
sharedEvents = 0;
MessageManager::instance->lockingLock.exit();
return;
}
@ -327,24 +329,26 @@ void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const
MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
locked = true;
needsUnlocking = true;
}
}
}
MessageManagerLock::~MessageManagerLock() throw()
{
if (sharedEvents != 0)
{
jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
sharedEvents->releaseEvent.signal();
sharedEvents->decReferenceCount();
if (MessageManager::instance != 0)
{
MessageManager::instance->threadWithLock = 0;
MessageManager::instance->lockingLock.exit();
}
}
}
MessageManagerLock::~MessageManagerLock() throw()
{
if (needsUnlocking && MessageManager::instance != 0)
{
jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
((SharedLockingEvents*) sharedEvents)->decReferenceCount();
MessageManager::instance->threadWithLock = 0;
MessageManager::instance->lockingLock.exit();
}
}
END_JUCE_NAMESPACE