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
qautoresetevent_pipe.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 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
#
include
"qautoresetevent_pipe_p.h"
5
6
#
include
<
QtCore
/
private
/
qcore_unix_p
.
h
>
7
#
include
<
QtCore
/
qdebug
.
h
>
8
9
#
include
<
unistd
.
h
>
10
#
include
<
cstdint
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
QtPrivate
{
15
16
QAutoResetEventPipe
::
QAutoResetEventPipe
(
QObject
*
parent
)
17
:
QObject
{
18
parent
,
19
},
20
m_notifier
{
21
QSocketNotifier
::
Type
::
Read
,
22
this
,
23
}
24
{
25
int
pipedes
[2];
26
int
status
=
pipe
(
pipedes
);
27
if
(
status
== -1) {
28
qCritical
() <<
"pipe failed:"
<<
qt_error_string
(
errno
);
29
return
;
30
}
31
32
m_fdConsumer
.
reset
(
pipedes
[0]);
33
m_fdProducer
.
reset
(
pipedes
[1]);
34
35
connect
(&
m_notifier
, &
QSocketNotifier
::
activated
,
this
, [
this
] {
36
QT_WARNING_PUSH
37
QT_WARNING_DISABLE_GCC
(
"-Wmaybe-uninitialized"
)
38
std
::
array
<
char
, 1024>
buffer
;
39
40
qint64
bytesRead
=
qt_safe_read
(
m_fdConsumer
.
get
(),
buffer
.
data
(),
buffer
.
size
());
41
Q_ASSERT
(
bytesRead
> 0);
42
43
m_consumePending
.
clear
();
44
Q_EMIT
activated
();
45
QT_WARNING_POP
46
});
47
m_notifier
.
setSocket
(
m_fdConsumer
.
get
());
48
m_notifier
.
setEnabled
(
true
);
49
}
50
51
void
QAutoResetEventPipe
::
set
()
52
{
53
Q_ASSERT
(
isValid
());
54
55
bool
consumePending
=
m_consumePending
.
test_and_set
();
56
if
(
consumePending
)
57
return
;
58
59
constexpr
uint8_t
dummy
{ 1 };
60
61
qint64
bytesWritten
=
qt_safe_write
(
m_fdProducer
.
get
(), &
dummy
,
sizeof
(
dummy
));
62
if
(
bytesWritten
== -1)
63
qCritical
(
"QAutoResetEvent::set failed"
);
64
}
65
66
}
// namespace QtPrivate
67
68
QT_END_NAMESPACE
69
70
#
include
"moc_qautoresetevent_pipe_p.cpp"
QtPrivate
Definition
qalloc.h:29
qtmultimedia
src
multimedia
support
qautoresetevent_pipe.cpp
Generated on
for Qt by
1.18.0