LMMS
Loading...
Searching...
No Matches
juce_MessageManager.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26class MessageManagerLock;
27class ThreadPoolJob;
28class ActionListener;
29class ActionBroadcaster;
30
31//==============================================================================
33using MessageCallbackFunction = void* (void* userData);
34
35
36//==============================================================================
45{
46public:
47 //==============================================================================
50
53
57 static void deleteInstance();
58
59 //==============================================================================
67 void runDispatchLoop();
68
76 void stopDispatchLoop();
77
81
82 #if JUCE_MODAL_LOOPS_PERMITTED
88 bool runDispatchLoopUntil (int millisecondsToRunFor);
89 #endif
90
91 //==============================================================================
97 static bool callAsync (std::function<void()> functionToCall);
98
117 void* callFunctionOnMessageThread (MessageCallbackFunction* callback, void* userData);
118
120 bool isThisTheMessageThread() const noexcept;
121
127 void setCurrentThreadAsMessageThread();
128
135
143 bool currentThreadHasLockedMessageManager() const noexcept;
144
148 static bool existsAndIsLockedByCurrentThread() noexcept;
149
153 static bool existsAndIsCurrentThread() noexcept;
154
155 //==============================================================================
162 static void broadcastMessage (const String& messageText);
163
171 void registerBroadcastListener (ActionListener* listener);
172
174 void deregisterBroadcastListener (ActionListener* listener);
175
176 //==============================================================================
182 {
183 public:
184 MessageBase() = default;
185 ~MessageBase() override = default;
186
187 virtual void messageCallback() = 0;
188 bool post();
189
191
193 };
194
195 //==============================================================================
200 {
201 public:
209 Lock();
210
212 ~Lock();
213
226 void enter() const noexcept;
227
271 bool tryEnter() const noexcept;
272
276 void exit() const noexcept;
277
285
286 //==============================================================================
289
292
295
296 private:
297 struct BlockingMessage;
299
300 bool tryAcquire (bool) const noexcept;
301 void messageCallback() const;
302
303 //==============================================================================
307 };
308
309 //==============================================================================
310 #ifndef DOXYGEN
311 // Internal methods - do not use!
312 void deliverBroadcastMessage (const String&);
314 #endif
315
316private:
317 //==============================================================================
319
321
322 friend class MessageBase;
323 class QuitMessage;
324 friend class QuitMessage;
325 friend class MessageManagerLock;
326
328 Atomic<int> quitMessagePosted { 0 }, quitMessageReceived { 0 };
331
333 static void* exitModalLoopCallback (void*);
335 static void doPlatformSpecificShutdown();
336
338};
339
340
341//==============================================================================
379{
380public:
381 //==============================================================================
423 MessageManagerLock (Thread* threadToCheckForExitSignal = nullptr);
424
425 //==============================================================================
431 MessageManagerLock (ThreadPoolJob* jobToCheckForExitSignal);
432
433 //==============================================================================
439 ~MessageManagerLock() override;
440
441 //==============================================================================
446
447private:
448 //==============================================================================
450 bool locked;
451
452 //==============================================================================
454 void exitSignalSent() override;
455
457};
458
459//==============================================================================
465#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED \
466 jassert (juce::MessageManager::existsAndIsLockedByCurrentThread());
467
473#define JUCE_ASSERT_MESSAGE_THREAD \
474 jassert (juce::MessageManager::existsAndIsCurrentThread());
475
479#define JUCE_ASSERT_MESSAGE_MANAGER_EXISTS \
480 jassert (juce::MessageManager::getInstanceWithoutCreating() != nullptr);
481
482
483} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
Definition juce_ActionBroadcaster.h:37
Definition juce_ActionListener.h:35
Definition juce_ScopedLock.h:55
Definition juce_ScopedLock.h:198
Definition juce_ScopedLock.h:126
Definition juce_MessageManager.h:200
WaitableEvent lockedEvent
Definition juce_MessageManager.h:305
Atomic< int > lockGained
Definition juce_MessageManager.h:306
Lock()
Definition juce_MessageManager.cpp:306
bool tryAcquire(bool) const noexcept
Definition juce_MessageManager.cpp:311
ReferenceCountedObjectPtr< BlockingMessage > blockingMessage
Definition juce_MessageManager.h:304
GenericScopedTryLock< Lock > ScopedTryLockType
Definition juce_MessageManager.h:294
void enter() const noexcept
Definition juce_MessageManager.cpp:308
void messageCallback() const
Definition juce_MessageManager.cpp:397
void abort() const noexcept
Definition juce_MessageManager.cpp:403
bool tryEnter() const noexcept
Definition juce_MessageManager.cpp:309
GenericScopedUnlock< Lock > ScopedUnlockType
Definition juce_MessageManager.h:291
GenericScopedLock< Lock > ScopedLockType
Definition juce_MessageManager.h:288
Atomic< int > abortWait
Definition juce_MessageManager.h:306
Definition juce_MessageManager.h:182
ReferenceCountedObjectPtr< MessageBase > Ptr
Definition juce_MessageManager.h:190
Definition juce_MessageManager.cpp:88
static MessageManager * instance
Definition juce_MessageManager.h:320
static void doPlatformSpecificShutdown()
Definition juce_linux_Messaging.cpp:310
static void doPlatformSpecificInitialisation()
Definition juce_linux_Messaging.cpp:301
static void * exitModalLoopCallback(void *)
void runDispatchLoop()
Definition juce_MessageManager.cpp:101
bool hasStopMessageBeenSent() const noexcept
Definition juce_MessageManager.h:80
friend class MessageManagerLock
Definition juce_MessageManager.h:325
void stopDispatchLoop()
Definition juce_MessageManager.cpp:116
Atomic< Thread::ThreadID > threadWithLock
Definition juce_MessageManager.h:330
Atomic< int > quitMessagePosted
Definition juce_MessageManager.h:328
Thread::ThreadID messageThreadId
Definition juce_MessageManager.h:329
std::unique_ptr< ActionBroadcaster > broadcaster
Definition juce_MessageManager.h:327
void deliverBroadcastMessage(const String &)
Definition juce_MessageManager.cpp:205
static bool postMessageToSystemQueue(MessageBase *)
Definition juce_linux_Messaging.cpp:316
Thread::ThreadID getCurrentMessageThread() const noexcept
Definition juce_MessageManager.h:134
static void deleteInstance()
Definition juce_MessageManager.cpp:63
static MessageManager * getInstanceWithoutCreating() noexcept
Definition juce_MessageManager.cpp:58
MessageManager() noexcept
Definition juce_MessageManager.cpp:26
static MessageManager * getInstance()
Definition juce_MessageManager.cpp:47
bool locked
Definition juce_MessageManager.h:450
bool attemptLock(Thread *, ThreadPoolJob *)
Definition juce_MessageManager.cpp:418
MessageManager::Lock mmLock
Definition juce_MessageManager.h:449
MessageManagerLock(Thread *threadToCheckForExitSignal=nullptr)
Definition juce_MessageManager.cpp:410
void exitSignalSent() override
Definition juce_MessageManager.cpp:457
bool lockWasGained() const noexcept
Definition juce_MessageManager.h:445
Definition juce_ReferenceCountedObject.h:247
Definition juce_String.h:53
Definition juce_Thread.h:181
Definition juce_Thread.h:43
void * ThreadID
Definition juce_Thread.h:304
Definition juce_ThreadPool.h:45
Definition juce_WaitableEvent.h:36
CARLA_PLUGIN_EXPORT void exit(int status)
Definition interposer-safe.cpp:70
#define JUCE_DECLARE_NON_COPYABLE(className)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
void *(void *userData) MessageCallbackFunction
Definition juce_MessageManager.h:33
Definition juce_Uuid.h:141
Definition juce_Atomic.h:42
Definition juce_MessageManager.cpp:281
RECT const char void(* callback)(const char *droppath))) SWELL_API_DEFINE(BOOL
Definition swell-functions.h:1004
ZCONST char * post
Definition fileio.c:2493
#define const
Definition zconf.h:137