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
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
5#include "qplatformdefs.h"
6#include "qmutex.h"
7#include "qstring.h"
8#include "qatomic.h"
9#include "qmutex_p.h"
10#include <errno.h>
11#include <sys/time.h>
12#include <time.h>
13#include "private/qcore_unix_p.h"
14
15#if defined(Q_OS_VXWORKS) && defined(wakeup)
16#undef wakeup
17#endif
18
20
21static void qt_report_error(int code, const char *where, const char *what)
22{
23 if (code != 0)
24 qErrnoWarning(code, "%s: %s failure", where, what);
25}
26
28{
29 qt_report_error(sem_init(&semaphore, 0, 0), "QMutex", "sem_init");
30}
31
33{
34
35 qt_report_error(sem_destroy(&semaphore), "QMutex", "sem_destroy");
36}
37
39{
40 int errorCode;
41 if (timeout.isForever()) {
42 do {
43 errorCode = sem_wait(&semaphore);
44 } while (errorCode && errno == EINTR);
45 qt_report_error(errorCode, "QMutex::lock()", "sem_wait");
46 } else {
47 do {
48 auto tp = timeout.deadline<std::chrono::system_clock>();
49 timespec ts = durationToTimespec(tp.time_since_epoch());
50 errorCode = sem_timedwait(&semaphore, &ts);
51 } while (errorCode && errno == EINTR);
52
53 if (errorCode && errno == ETIMEDOUT)
54 return false;
55 qt_report_error(errorCode, "QMutex::lock()", "sem_timedwait");
56 }
57 return true;
58}
59
60void QMutexPrivate::wakeUp() noexcept
61{
62 qt_report_error(sem_post(&semaphore), "QMutex::unlock", "sem_post");
63}
64
\inmodule QtCore
bool wait(QDeadlineTimer timeout=QDeadlineTimer::Forever)
void wakeUp() noexcept
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
static QT_BEGIN_NAMESPACE void qt_report_error(int code, const char *where, const char *what)
GLbitfield GLuint64 timeout
[4]