Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfutex_freebsd_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
4#ifndef QFUTEX_FREEBSD_P_H
5#define QFUTEX_FREEBSD_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qcore_unix_p.h>
19#include <qdeadlinetimer.h>
20
21// https://man.freebsd.org/cgi/man.cgi?query=_umtx_op
22#include <sys/umtx.h>
23
24#define QT_ALWAYS_USE_FUTEX
25
27
28namespace QtFreeBSDFutex {
29constexpr inline bool futexAvailable() { return true; }
30
31template <typename Atomic>
32inline int do_wait(Atomic &futex, typename Atomic::Type expectedValue, _umtx_time *tmp = nullptr)
33{
34 // FreeBSD UMTX_OP_WAIT does not apply acquire or release memory barriers,
35 // so there are no QtTsan calls here.
36
37 int op = UMTX_OP_WAIT_UINT_PRIVATE;
38 if (sizeof(futex) > sizeof(quint32))
39 op = UMTX_OP_WAIT; // no _PRIVATE version
40
41 // The timeout is passed in uaddr2, with its size in uaddr
42 void *uaddr = reinterpret_cast<void *>(tmp ? sizeof(*tmp) : 0);
43 void *uaddr2 = tmp;
44 int ret = _umtx_op(&futex, op, u_long(expectedValue), uaddr, uaddr2);
45
46 return ret;
47}
48
49template <typename Atomic>
50inline void futexWait(Atomic &futex, typename Atomic::Type expectedValue)
51{
52 do_wait(futex, expectedValue);
53}
54
55template <typename Atomic>
56inline bool futexWait(Atomic &futex, typename Atomic::Type expectedValue, QDeadlineTimer timer)
57{
58 struct _umtx_time tm = {};
59 auto deadline = timer.deadline<std::chrono::steady_clock>();
60 tm._timeout = durationToTimespec(deadline.time_since_epoch());
61 tm._flags = UMTX_ABSTIME;
62 tm._clockid = CLOCK_MONOTONIC;
63 int r = do_wait(futex, expectedValue, &tm);
64 return r == 0 || errno != ETIMEDOUT;
65}
66
67template <typename Atomic> inline void futexWakeOne(Atomic &futex)
68{
69 _umtx_op(&futex, UMTX_OP_WAKE_PRIVATE, 1, nullptr, nullptr);
70}
71
72template <typename Atomic> inline void futexWakeAll(Atomic &futex)
73{
74 _umtx_op(&futex, UMTX_OP_WAKE_PRIVATE, INT_MAX, nullptr, nullptr);
75}
76} //namespace QtFreeBSDFutex
77
78namespace QtFutex = QtFreeBSDFutex;
79
81
82#endif // QFUTEX_FREEBSD_P_H
\inmodule QtCore
Combined button and popup list for selecting options.
void futexWakeAll(Atomic &futex)
void futexWait(Atomic &futex, typename Atomic::Type expectedValue)
void futexWakeOne(Atomic &futex)
int do_wait(Atomic &futex, typename Atomic::Type expectedValue, _umtx_time *tmp=nullptr)
constexpr bool futexAvailable()
timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
return ret
GLboolean r
[2]
unsigned int quint32
Definition qtypes.h:50
QDeadlineTimer deadline(30s)
QTimer * timer
[3]