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
qaudiostatemachineutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
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 QAUDIOSTATEMACHINEUTILS_P_H
5#define QAUDIOSTATEMACHINEUTILS_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 "qaudio.h"
19
21
23
24using RawState = int;
25
26constexpr uint32_t AudioStateBitsCount = 8;
27constexpr RawState AudioStateMask = 0xFF;
28constexpr RawState AudioErrorMask = 0xFF00;
29constexpr RawState DrainingFlag = 0x10000;
30
33 "Invalid masks");
34
36{
37 return (state & DrainingFlag) != 0;
38}
39
41{
42 return state | DrainingFlag;
43}
44
46{
47 return state & ~DrainingFlag;
48}
49
54
59
64
66{
67 return (error << AudioStateBitsCount) | (state & ~AudioErrorMask);
68}
69
70template <typename... States>
72{
73 return [=](RawState state) {
75 return (... || (state == states));
76 };
77}
78
79// ensures compareExchange (testAndSet) operation with opportunity
80// to check several states, can be considered as atomic
81template <typename T, typename Predicate, typename NewValueGetter>
82bool multipleCompareExchange(std::atomic<T> &target, T &prevValue, Predicate predicate,
83 NewValueGetter newValueGetter)
84{
85 while (predicate(prevValue))
86 if (target.compare_exchange_strong(prevValue, newValueGetter(prevValue),
87 std::memory_order_acq_rel))
88 return true;
89
90 return false;
91}
92} // namespace AudioStateMachineUtils
93
95
96#endif // QAUDIOSTATEMACHINEUTILS_P_H
const auto predicate
else opt state
[0]
constexpr bool isDrainingState(RawState state)
constexpr uint32_t AudioStateBitsCount
constexpr auto makeStatesChecker(States... states)
constexpr RawState removeDrainingFlag(RawState state)
constexpr QAudio::State toAudioState(RawState state)
constexpr RawState setStateError(RawState state, QAudio::Error error)
constexpr RawState toRawState(QAudio::State state, QAudio::Error error=QAudio::NoError)
constexpr RawState addDrainingFlag(RawState state)
constexpr QAudio::Error toAudioError(RawState state)
bool multipleCompareExchange(std::atomic< T > &target, T &prevValue, Predicate predicate, NewValueGetter newValueGetter)
State
Definition qaudio.h:29
Error
Definition qaudio.h:28
@ NoError
Definition qaudio.h:28
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLenum target
GLuint * states