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
qmutex_unix.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
include
"qplatformdefs.h"
7
#
include
"qmutex.h"
8
#
include
"qstring.h"
9
#
include
"qatomic.h"
10
#
include
"qmutex_p.h"
11
#
include
<
errno
.
h
>
12
#
include
<
sys
/
time
.
h
>
13
#
include
<
time
.
h
>
14
#
include
"private/qcore_unix_p.h"
15
16
#
if
defined
(
Q_OS_VXWORKS
)
&&
defined
(
wakeup
)
17
#
undef
wakeup
18
#
endif
19
20
QT_BEGIN_NAMESPACE
21
22
static
void
qt_report_error
(
int
code,
const
char
*where,
const
char
*what)
23
{
24
if
(code != 0)
25
qErrnoWarning(code,
"%s: %s failure"
, where, what);
26
}
27
28
QMutexPrivate::QMutexPrivate()
29
{
30
qt_report_error(sem_init(&semaphore, 0, 0),
"QMutex"
,
"sem_init"
);
31
}
32
33
QMutexPrivate::~QMutexPrivate()
34
{
35
36
qt_report_error(sem_destroy(&semaphore),
"QMutex"
,
"sem_destroy"
);
37
}
38
39
bool
QMutexPrivate::wait(QDeadlineTimer timeout)
40
{
41
int
errorCode;
42
if
(timeout.isForever()) {
43
do
{
44
errorCode = sem_wait(&semaphore);
45
}
while
(errorCode && errno == EINTR);
46
qt_report_error
(
errorCode
,
"QMutex::lock()"
,
"sem_wait"
)
;
47
}
else
{
48
do
{
49
auto
tp = timeout.deadline<
std
::chrono::system_clock>();
50
timespec ts = durationToTimespec(tp.time_since_epoch());
51
errorCode = sem_timedwait(&semaphore, &ts);
52
}
while
(errorCode && errno == EINTR);
53
54
if
(errorCode && errno == ETIMEDOUT)
55
return
false
;
56
qt_report_error
(
errorCode
,
"QMutex::lock()"
,
"sem_timedwait"
)
;
57
}
58
return
true
;
59
}
60
61
void
QMutexPrivate::wakeUp()
noexcept
62
{
63
qt_report_error(sem_post(&semaphore),
"QMutex::unlock"
,
"sem_post"
);
64
}
65
66
QT_END_NAMESPACE
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qt_report_error
static QT_BEGIN_NAMESPACE void qt_report_error(int code, const char *where, const char *what)
Definition
qmutex_unix.cpp:22
qtbase
src
corelib
thread
qmutex_unix.cpp
Generated on
for Qt by
1.18.0