LMMS
Loading...
Searching...
No Matches
juce_DeletedAtShutdown.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
26static SpinLock deletedAtShutdownLock; // use a spin lock because it can be statically initialised
27
29{
30 static Array<DeletedAtShutdown*> objects;
31 return objects;
32}
33
39
45
46// Disable unreachable code warning, in case the compiler manages to figure out that
47// you have no classes of DeletedAtShutdown that could throw an exception in their destructor.
49
51{
52 // make a local copy of the array, so it can't get into a loop if something
53 // creates another DeletedAtShutdown object during its destructor.
55
56 {
58 localCopy = getDeletedAtShutdownObjects();
59 }
60
61 for (int i = localCopy.size(); --i >= 0;)
62 {
63 JUCE_TRY
64 {
65 auto* deletee = localCopy.getUnchecked(i);
66
67 // double-check that it's not already been deleted during another object's destructor.
68 {
69 const SpinLock::ScopedLockType sl (deletedAtShutdownLock);
70
71 if (! getDeletedAtShutdownObjects().contains (deletee))
72 deletee = nullptr;
73 }
74
75 delete deletee;
76 }
78 }
79
80 // if this fails, then it's likely that some new DeletedAtShutdown objects were
81 // created while executing the destructors of the other ones.
83
84 getDeletedAtShutdownObjects().clear(); // just to make sure the array doesn't have any memory still allocated
85}
86
88
89} // namespace juce
Definition juce_Array.h:56
int size() const noexcept
Definition juce_Array.h:215
static void deleteAll()
Definition juce_DeletedAtShutdown.cpp:50
virtual ~DeletedAtShutdown()
Definition juce_DeletedAtShutdown.cpp:40
DeletedAtShutdown()
Definition juce_DeletedAtShutdown.cpp:34
Definition juce_SpinLock.h:42
GenericScopedLock< SpinLock > ScopedLockType
Definition juce_SpinLock.h:73
register unsigned i
Definition inflate.c:1575
#define JUCE_CATCH_EXCEPTION
Definition juce_ApplicationBase.h:330
#define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings)
Definition juce_CompilerWarnings.h:198
#define JUCE_END_IGNORE_WARNINGS_MSVC
Definition juce_CompilerWarnings.h:199
#define jassert(expression)
Definition carla_juce.cpp:31
static Array< DeletedAtShutdown * > & getDeletedAtShutdownObjects()
Definition juce_DeletedAtShutdown.cpp:28
static SpinLock deletedAtShutdownLock
Definition juce_DeletedAtShutdown.cpp:26
#define void
Definition unzip.h:396