Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfutex_mac_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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 QFUTEX_MAC_P_H
6#define QFUTEX_MAC_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
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <qdeadlinetimer.h>
20#include <qtsan_impl.h>
21#include <private/qglobal_p.h>
22
23#include <os/os_sync_wait_on_address.h>
24
25#define QT_ALWAYS_USE_FUTEX
26
28
29namespace QtDarwinFutex {
30
31constexpr bool futexAvailable() { return true; }
32
33template <typename Atomic>
34inline void futexWait(Atomic &futex, typename Atomic::Type expectedValue)
35{
37 static_assert(sizeof(typename Atomic::Type) == 4 || sizeof(typename Atomic::Type) == 8);
38 os_sync_wait_on_address(&futex, quint64(expectedValue), sizeof(typename Atomic::Type),
39 OS_SYNC_WAIT_ON_ADDRESS_NONE);
41}
42
43template <typename Atomic>
44inline bool futexWait(Atomic &futex, typename Atomic::Type expectedValue, QDeadlineTimer timer)
45{
47 static_assert(sizeof(typename Atomic::Type) == 4 || sizeof(typename Atomic::Type) == 8);
48 int r = os_sync_wait_on_address_with_timeout(
49 &futex, quint64(expectedValue), sizeof(typename Atomic::Type),
50 OS_SYNC_WAIT_ON_ADDRESS_NONE, OS_CLOCK_MACH_ABSOLUTE_TIME, timer.remainingTimeNSecs());
52 return r >= 0 || errno != ETIMEDOUT;
53}
54
55template <typename Atomic>
56inline void futexWakeAll(Atomic &futex)
57{
58 static_assert(sizeof(typename Atomic::Type) == 4 || sizeof(typename Atomic::Type) == 8);
59 os_sync_wake_by_address_all(&futex, sizeof(typename Atomic::Type),
60 OS_SYNC_WAKE_BY_ADDRESS_NONE);
61}
62
63template <typename Atomic>
64inline void futexWakeOne(Atomic &futex)
65{
66 static_assert(sizeof(typename Atomic::Type) == 4 || sizeof(typename Atomic::Type) == 8);
67 os_sync_wake_by_address_any(&futex, sizeof(typename Atomic::Type),
68 OS_SYNC_WAKE_BY_ADDRESS_NONE);
69}
70} //namespace QtDarwinFutex
71
72namespace QtFutex = QtDarwinFutex;
73
74QT_END_NAMESPACE
75
76#endif // QFUTEX_MAC_P_H
Combined button and popup list for selecting options.
constexpr bool futexAvailable()
void futexWakeOne(Atomic &futex)
void futexWait(Atomic &futex, typename Atomic::Type expectedValue)
void futexWakeAll(Atomic &futex)
bool futexWait(Atomic &futex, typename Atomic::Type expectedValue, QDeadlineTimer timer)
void futexRelease(void *, void *=nullptr)
Definition qtsan_impl.h:75
void futexAcquire(void *, void *=nullptr)
Definition qtsan_impl.h:74