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
qautoresetevent_kqueue.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 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_kqueue_p.h"
5
6
#
include
<
QtCore
/
private
/
qcore_unix_p
.
h
>
7
#
include
<
QtCore
/
qdebug
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
namespace
QtPrivate
{
12
13
QAutoResetEventKQueue
::
QAutoResetEventKQueue
(
QObject
*
parent
):
14
QObject
{
15
parent
,
16
},
17
m_notifier
{
18
QSocketNotifier
::
Type
::
Read
,
19
}
20
{
21
m_kqueue
=
kqueue
();
22
if
(
m_kqueue
== -1) {
23
qCritical
() <<
"kqueue failed:"
<<
qt_error_string
(
errno
);
24
return
;
25
}
26
27
// Register a custom EVFILT_USER event with the EV_CLEAR flag.
28
// The EV_CLEAR flag causes the event to auto-reset once it is delivered.
29
EV_SET
(&
m_event
, 1,
EVFILT_USER
,
EV_ADD
|
EV_CLEAR
, 0, 0,
nullptr
);
30
if
(
kevent
(
m_kqueue
, &
m_event
, 1,
nullptr
, 0,
nullptr
) == -1) {
31
close
(
m_kqueue
);
32
qCritical
() <<
"Failed to register EVFILT_USER event:"
<<
qt_error_string
(
errno
);
33
return
;
34
}
35
36
connect
(&
m_notifier
, &
QSocketNotifier
::
activated
,
this
, [
this
] {
37
struct
kevent
ev
;
38
int
nev
=
kevent
(
m_kqueue
,
nullptr
, 0, &
ev
, 1,
nullptr
);
39
if
(
nev
> 0)
40
emit
activated
();
41
});
42
m_notifier
.
setSocket
(
m_kqueue
);
43
m_notifier
.
setEnabled
(
true
);
44
}
45
46
QAutoResetEventKQueue
::~
QAutoResetEventKQueue
()
47
{
48
if
(
m_kqueue
!= -1)
49
qt_safe_close
(
m_kqueue
);
50
}
51
52
void
QAutoResetEventKQueue
::
set
()
53
{
54
Q_ASSERT
(
isValid
());
55
56
EV_SET
(&
m_event
, 1,
EVFILT_USER
, 0,
NOTE_TRIGGER
, 0,
nullptr
);
57
58
if
(
kevent
(
m_kqueue
, &
m_event
, 1,
nullptr
, 0,
nullptr
) == -1)
59
qWarning
() <<
"Failed to signal event"
;
60
}
61
62
bool
QAutoResetEventKQueue
::
isValid
()
const
63
{
64
return
m_kqueue
!= -1;
65
}
66
67
}
// namespace QtPrivate
68
69
QT_END_NAMESPACE
70
71
#
include
"moc_qautoresetevent_kqueue_p.cpp"
QPlatformGraphicsBufferHelper
\inmodule QtGui
QtPrivate
Definition
qalloc.h:27
qtmultimedia
src
multimedia
audio
qautoresetevent_kqueue.cpp
Generated on
for Qt by
1.14.0