Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qatomicwait_p.h
Go to the documentation of this file.
1
// Copyright (C) 2025 Intel Corporation.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
QATOMICWAIT_P_H
6
#
define
QATOMICWAIT_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an implementation
13
// detail. This header file may change from version to version without notice,
14
// or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
"qbasicatomic.h"
20
#
include
<
private
/
qglobal_p
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
namespace
QtPrivate
{
25
enum
class
WakeMode
{
One
= 1,
All
= -1 };
26
27
#
ifdef
QATOMICWAIT_USE_FALLBACK
28
#
define
Q_ATOMICWAIT_EXPORT
/* being linked into the unit test */
29
#
else
30
#
define
Q_ATOMICWAIT_EXPORT
Q_CORE_EXPORT
31
#
endif
32
33
Q_ATOMICWAIT_EXPORT
void
_q_atomicWait
(
const
void
*address,
const
void
*old, qsizetype size)
noexcept
;
34
Q_ATOMICWAIT_EXPORT
void
_q_atomicWake
(
void
*address,
WakeMode
)
noexcept
;
35
36
#
undef
Q_ATOMICWAIT_EXPORT
37
}
38
39
namespace
QtFallbackAtomicWait
{
40
// C++20- & C23-like API
41
template
<
typename
T
>
std
::
enable_if_t
<
std
::
has_unique_object_representations_v
<
T
>>
42
atomic_wait_explicit
(
const
std
::
atomic
<
T
> *
atomic
,
T
old
,
std
::
memory_order
mo
)
noexcept
43
{
44
Q_ASSERT
(
mo
==
std
::
memory_order_relaxed
||
mo
==
std
::
memory_order_acquire
45
||
mo
==
std
::
memory_order_seq_cst
);
46
QtPrivate
::
_q_atomicWait
(
atomic
, &
old
,
sizeof
(
T
));
47
// TSAN does not support atomic_thread_fence and GCC complains (QTBUG-134415)
48
QT_WARNING_PUSH
49
#
if
defined
(
Q_CC_GNU_ONLY
)
&&
Q_CC_GNU
>=
1100
50
QT_WARNING_DISABLE_GCC
(
"-Wtsan"
)
51
#
endif
52
std
::
atomic_thread_fence
(
mo
);
53
QT_WARNING_POP
54
}
55
56
template
<
typename
T
>
std
::
enable_if_t
<
std
::
has_unique_object_representations_v
<
T
>>
57
atomic_wait
(
const
std
::
atomic
<
T
> *
atomic
,
T
old
)
noexcept
58
{
59
atomic_wait_explicit
(
atomic
,
old
,
std
::
memory_order_seq_cst
);
60
}
61
62
template
<
typename
T
>
std
::
enable_if_t
<
std
::
has_unique_object_representations_v
<
T
>>
63
atomic_notify_one
(
std
::
atomic
<
T
> *
atomic
)
64
{
65
QtPrivate
::
_q_atomicWake
(
atomic
,
QtPrivate
::
WakeMode
::
One
);
66
}
67
68
template
<
typename
T
>
std
::
enable_if_t
<
std
::
has_unique_object_representations_v
<
T
>>
69
atomic_notify_all
(
std
::
atomic
<
T
> *
atomic
)
70
{
71
QtPrivate
::
_q_atomicWake
(
atomic
,
QtPrivate
::
WakeMode
::
All
);
72
}
73
}
// namespace QtFallbackAtomicWait
74
75
namespace
q20
{
76
#
ifdef
__cpp_lib_atomic_wait
77
using
std
::
atomic_wait
;
78
using
std
::
atomic_wait_explicit
;
79
using
std
::
atomic_notify_all
;
80
using
std
::
atomic_notify_one
;
81
#
else
82
using
QtFallbackAtomicWait
::atomic_wait;
83
using
QtFallbackAtomicWait
::atomic_wait_explicit;
84
using
QtFallbackAtomicWait
::atomic_notify_all;
85
using
QtFallbackAtomicWait
::atomic_notify_one;
86
#
endif
87
}
// namespace QtNativeAtomicWait
88
89
QT_END_NAMESPACE
90
91
#
endif
// QATOMICWAIT_P_H
QtDummyFutex::futexAvailable
constexpr bool futexAvailable()
Definition
qfutex_p.h:25
QtFallbackAtomicWait
Definition
qatomicwait_p.h:39
QtPrivate
Definition
qalloc.h:29
QtPrivate::_q_atomicWake
Q_ATOMICWAIT_EXPORT void _q_atomicWake(void *address, WakeMode) noexcept
Definition
qatomicwait.cpp:163
QtPrivate::_q_atomicWait
Q_ATOMICWAIT_EXPORT void _q_atomicWait(const void *address, const void *old, qsizetype size) noexcept
Definition
qatomicwait.cpp:138
QtPrivate::WakeMode
WakeMode
Definition
qatomicwait_p.h:25
QtPrivate::WakeMode::One
@ One
Definition
qatomicwait_p.h:25
QtPrivate::WakeMode::All
@ All
Definition
qatomicwait_p.h:25
q20
Definition
qnumeric.cpp:467
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
isEqual
static bool isEqual(const void *address, const void *old)
Definition
qatomicwait.cpp:120
isEqual
static bool isEqual(const void *address, const void *old, qsizetype size) noexcept
Definition
qatomicwait.cpp:127
checkFutexUse
static void checkFutexUse()
Definition
qatomicwait.cpp:101
atomicLocks
static QAtomicWaitLocks & atomicLocks() noexcept
Definition
qatomicwait.cpp:112
Q_ATOMICWAIT_EXPORT
#define Q_ATOMICWAIT_EXPORT
Definition
qatomicwait_p.h:30
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::Lock
Definition
qatomicwait.cpp:67
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::Lock::watchedAddress
const void * watchedAddress
Definition
qatomicwait.cpp:75
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::Lock::cond
std::condition_variable cond
Definition
qatomicwait.cpp:69
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::Lock::watcherCount
qsizetype watcherCount
Definition
qatomicwait.cpp:76
QT_BEGIN_NAMESPACE::QAtomicWaitLocks
Definition
qatomicwait.cpp:62
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::indexFor
int indexFor(const void *ptr)
Definition
qatomicwait.cpp:82
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::locks
std::array< Lock, LockCount > locks
Definition
qatomicwait.cpp:80
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::contendedWatchAddress
static void * contendedWatchAddress()
Definition
qatomicwait.cpp:65
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::LockCount
static constexpr int LockCount
Definition
qatomicwait.cpp:79
QT_BEGIN_NAMESPACE::QAtomicWaitLocks::lockFor
Lock & lockFor(const void *ptr)
Definition
qatomicwait.cpp:97
qtbase
src
corelib
thread
qatomicwait_p.h
Generated on
for Qt by
1.18.0