blob: 6bd69c66d14e675f8de667bec3ae1bc6a995de3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qfactorycacheregistration_p.h"
#include <QtCore/QMutex>
QT_BEGIN_NAMESPACE
#ifdef QT_USE_FACTORY_CACHE_REGISTRATION
static QBasicMutex registrationMutex;
static detail::QWinRTFactoryCacheRegistration *firstElement;
detail::QWinRTFactoryCacheRegistration::QWinRTFactoryCacheRegistration(
QFunctionPointer clearFunction)
: m_clearFunction(clearFunction)
{
QMutexLocker lock(®istrationMutex);
// forward pointers
m_next = std::exchange(firstElement, this);
// backward pointers
m_prevNext = &firstElement;
if (m_next)
m_next->m_prevNext = &m_next;
}
detail::QWinRTFactoryCacheRegistration::~QWinRTFactoryCacheRegistration()
{
QMutexLocker lock(®istrationMutex);
*m_prevNext = m_next;
if (m_next)
m_next->m_prevNext = m_prevNext;
}
void detail::QWinRTFactoryCacheRegistration::clearAllCaches()
{
QMutexLocker lock(®istrationMutex);
detail::QWinRTFactoryCacheRegistration *element;
for (element = firstElement; element != nullptr; element = element->m_next) {
element->m_clearFunction();
}
}
#endif
QT_END_NAMESPACE
|