OpenShot Library | libopenshot-audio
0.2.0
|
26 MessageManager::MessageManager() noexcept
27 : messageThreadId (Thread::getCurrentThreadId())
33 MessageManager::~MessageManager() noexcept
37 doPlatformSpecificShutdown();
39 jassert (instance ==
this);
43 MessageManager* MessageManager::instance =
nullptr;
47 if (instance ==
nullptr)
50 doPlatformSpecificInitialisation();
63 deleteAndZero (instance);
67 bool MessageManager::MessageBase::post()
69 auto* mm = MessageManager::instance;
71 if (mm ==
nullptr || mm->quitMessagePosted.get() != 0 || ! postMessageToSystemQueue (
this))
81 #if JUCE_MODAL_LOOPS_PERMITTED && ! (JUCE_MAC || JUCE_IOS)
88 while (quitMessageReceived.
get() == 0)
92 if (! dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
101 return quitMessageReceived.
get() == 0;
105 #if ! (JUCE_MAC || JUCE_IOS || JUCE_ANDROID)
111 void messageCallback()
override
113 if (
auto* mm = MessageManager::instance)
114 mm->quitMessageReceived =
true;
117 JUCE_DECLARE_NON_COPYABLE (QuitMessage)
124 while (quitMessageReceived.
get() == 0)
128 if (! dispatchNextMessageOnSystemQueue (
false))
137 (
new QuitMessage())->post();
138 quitMessagePosted =
true;
148 : func (f), parameter (param)
151 void messageCallback()
override
153 result = (*func) (parameter);
158 std::atomic<void*> result {
nullptr };
161 MessageCallbackFunction*
const func;
162 void*
const parameter;
170 return func (parameter);
179 message->finished.wait();
180 return message->result.load();
188 void MessageManager::deliverBroadcastMessage (
const String& value)
190 if (broadcaster !=
nullptr)
191 broadcaster->sendActionMessage (value);
196 if (broadcaster ==
nullptr)
199 broadcaster->addActionListener (listener);
204 if (broadcaster !=
nullptr)
205 broadcaster->removeActionListener (listener);
218 if (messageThreadId != thisThread)
220 messageThreadId = thisThread;
223 doPlatformSpecificShutdown();
224 doPlatformSpecificInitialisation();
231 return thisThread == messageThreadId || thisThread == threadWithLock.
get();
237 return i->currentThreadHasLockedMessageManager();
245 return i->isThisTheMessageThread();
267 void messageCallback()
override
272 if (
auto* o = owner.get())
273 o->messageCallback();
292 bool MessageManager::Lock::tryAcquire (
bool lockIsMandatory)
const noexcept
294 auto* mm = MessageManager::instance;
302 if (! lockIsMandatory && (abortWait.get() != 0))
308 if (mm->currentThreadHasLockedMessageManager())
313 blockingMessage = *
new BlockingMessage (
this);
317 jassert (! lockIsMandatory);
321 if (! blockingMessage->post())
324 jassert (! lockIsMandatory);
325 blockingMessage =
nullptr;
331 while (abortWait.get() == 0)
332 lockedEvent.wait (-1);
336 if (lockGained.get() != 0)
342 }
while (lockIsMandatory);
345 blockingMessage->releaseEvent.signal();
348 ScopedLock lock (blockingMessage->ownerCriticalSection);
351 blockingMessage->owner.set (
nullptr);
354 blockingMessage =
nullptr;
360 if (lockGained.compareAndSetBool (
false,
true))
362 auto* mm = MessageManager::instance;
364 jassert (mm ==
nullptr || mm->currentThreadHasLockedMessageManager());
368 mm->threadWithLock = {};
370 if (blockingMessage !=
nullptr)
372 blockingMessage->releaseEvent.signal();
373 blockingMessage =
nullptr;
378 void MessageManager::Lock::messageCallback()
const
387 lockedEvent.signal();
392 : locked (attemptLock (threadToCheck, nullptr))
396 : locked (attemptLock (nullptr, jobToCheck))
401 jassert (threadToCheck ==
nullptr || jobToCheck ==
nullptr);
403 if (threadToCheck !=
nullptr)
406 if (jobToCheck !=
nullptr)
411 && (jobToCheck ==
nullptr || ! jobToCheck->
shouldExit()))
417 if (threadToCheck !=
nullptr)
425 if (jobToCheck !=
nullptr)
438 void MessageManagerLock::exitSignalSent()
444 JUCE_API void JUCE_CALLTYPE initialiseJuce_GUI();
445 JUCE_API void JUCE_CALLTYPE initialiseJuce_GUI()
453 JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI();
454 JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI()
463 static int numScopedInitInstances = 0;
A simple wrapper around std::atomic.
Manages a list of ActionListeners, and can send them messages.
bool isThisTheMessageThread() const noexcept
Returns true if the caller-thread is the message thread.
Internal class used as the base class for all message objects.
bool tryEnter() const noexcept
Attempts to lock the meesage manager and exits if abort is called.
A task that is executed by a ThreadPool object.
void registerBroadcastListener(ActionListener *listener)
Registers a listener to get told about broadcast messages.
ScopedJuceInitialiser_GUI()
The constructor simply calls initialiseJuce_GUI().
Type get() const noexcept
Atomically reads and returns the current value.
MessageManagerLock(Thread *threadToCheckForExitSignal=nullptr)
Tries to acquire a lock on the message manager.
static bool existsAndIsCurrentThread() noexcept
Returns true if there's an instance of the MessageManager, and if the current thread is running it.
static void deleteInstance()
Deletes the global MessageManager instance.
static int64 currentTimeMillis() noexcept
Returns the current system time.
static void JUCE_CALLTYPE setCurrentThreadName(const String &newThreadName)
Changes the name of the caller thread.
void enter() const noexcept
Acquires the message manager lock.
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Returns an id that identifies the caller thread.
bool threadShouldExit() const
Checks whether the thread has been told to stop running.
void setCurrentThreadAsMessageThread()
Called to tell the manager that the current thread is the one that's running the dispatch loop.
#define JUCE_API
This macro is added to all JUCE public class declarations.
static MessageManager * getInstance()
Returns the global instance of the MessageManager.
void exit() const noexcept
Releases the message manager lock.
void addListener(Listener *)
Add a listener to this thread which will receive a callback when signalThreadShouldExit was called on...
static bool isStandaloneApp() noexcept
Returns true if this executable is running as an app (as opposed to being a plugin or other kind of s...
bool currentThreadHasLockedMessageManager() const noexcept
Returns true if the caller thread has currently got the message manager locked.
This class is in charge of the application's event-dispatch loop.
void removeListener(Thread::Listener *)
Removes a listener added with addListener.
Lock()
Creates a new critical section to exclusively access methods which can only be called when the messag...
void runDispatchLoop()
Runs the event dispatch loop until a stop message is posted.
~MessageManagerLock() override
Releases the current thread's lock on the message manager.
~ScopedJuceInitialiser_GUI()
The destructor simply calls shutdownJuce_GUI().
static void deleteAll()
Deletes all extant objects.
Automatically locks and unlocks a mutex object.
void addListener(Thread::Listener *)
Add a listener to this thread job which will receive a callback when signalJobShouldExit was called o...
A smart-pointer class which points to a reference-counted object.
void removeListener(Listener *)
Removes a listener added with addListener.
void deregisterBroadcastListener(ActionListener *listener)
Deregisters a broadcast listener.
bool runDispatchLoopUntil(int millisecondsToRunFor)
Synchronously dispatches messages until a given time has elapsed.
bool shouldExit() const noexcept
Returns true if something is trying to interrupt this job and make it stop.
A lock you can use to lock the message manager.
void * callFunctionOnMessageThread(MessageCallbackFunction *callback, void *userData)
Calls a function using the message-thread.
static MessageManager * getInstanceWithoutCreating() noexcept
Returns the global instance of the MessageManager, or nullptr if it doesn't exist.
void abort() const noexcept
Unblocks a thread which is waiting in tryEnter Call this method if you want to unblock a thread which...
static bool existsAndIsLockedByCurrentThread() noexcept
Returns true if there's an instance of the MessageManager, and if the current thread has the lock on ...
Interface class for delivery of events that are sent by an ActionBroadcaster.
void stopDispatchLoop()
Sends a signal that the dispatch loop should terminate.
static void JUCE_CALLTYPE sleep(int milliseconds)
Suspends the execution of the current thread until the specified timeout period has elapsed (note tha...
Allows threads to wait for events triggered by other threads.