LMMS
Loading...
Searching...
No Matches
juce_AsyncUpdater.cpp
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
27{
28public:
30
31 void messageCallback() override
32 {
33 if (shouldDeliver.compareAndSetBool (0, 1))
34 owner.handleAsyncUpdate();
35 }
36
39
41};
42
43//==============================================================================
48
50{
51 // You're deleting this object with a background thread while there's an update
52 // pending on the main event thread - that's pretty dodgy threading, as the callback could
53 // happen after this destructor has finished. You should either use a MessageManagerLock while
54 // deleting this object, or find some other way to avoid such a race condition.
57 || MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager());
58
59 activeMessage->shouldDeliver.set (0);
60}
61
63{
64 // If you're calling this before (or after) the MessageManager is
65 // running, then you're not going to get any callbacks!
67
68 if (activeMessage->shouldDeliver.compareAndSetBool (1, 0))
69 if (! activeMessage->post())
70 cancelPendingUpdate(); // if the message queue fails, this avoids getting
71 // trapped waiting for the message to arrive
72}
73
75{
76 activeMessage->shouldDeliver.set (0);
77}
78
80{
81 // This can only be called by the event thread.
83
84 if (activeMessage->shouldDeliver.exchange (0) != 0)
86}
87
89{
90 return activeMessage->shouldDeliver.value != 0;
91}
92
93} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AsyncUpdater.cpp:27
Atomic< int > shouldDeliver
Definition juce_AsyncUpdater.cpp:38
AsyncUpdaterMessage(AsyncUpdater &au)
Definition juce_AsyncUpdater.cpp:29
void messageCallback() override
Definition juce_AsyncUpdater.cpp:31
AsyncUpdater & owner
Definition juce_AsyncUpdater.cpp:37
bool isUpdatePending() const noexcept
Definition juce_AsyncUpdater.cpp:88
ReferenceCountedObjectPtr< AsyncUpdaterMessage > activeMessage
Definition juce_AsyncUpdater.h:105
void handleUpdateNowIfNeeded()
Definition juce_AsyncUpdater.cpp:79
virtual void handleAsyncUpdate()=0
virtual ~AsyncUpdater()
Definition juce_AsyncUpdater.cpp:49
void triggerAsyncUpdate()
Definition juce_AsyncUpdater.cpp:62
void cancelPendingUpdate() noexcept
Definition juce_AsyncUpdater.cpp:74
AsyncUpdater()
Definition juce_AsyncUpdater.cpp:44
static MessageManager * getInstanceWithoutCreating() noexcept
Definition juce_MessageManager.cpp:58
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
Definition juce_MessageManager.h:465
#define JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
Definition juce_MessageManager.h:479
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition carla_juce.cpp:31
Definition juce_Atomic.h:42
#define const
Definition zconf.h:137