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_mac.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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 "qplatformdefs.h"
5
#include "
qmutex.h
"
6
#include "
qmutex_p.h
"
7
8
#include "private/qcore_unix_p.h"
9
10
#include <mach/mach.h>
11
#include <mach/task.h>
12
13
#include <errno.h>
14
15
QT_BEGIN_NAMESPACE
16
17
QMutexPrivate::QMutexPrivate
()
18
{
19
kern_return_t
r
= semaphore_create(mach_task_self(), &mach_semaphore, SYNC_POLICY_FIFO, 0);
20
if
(
r
!= KERN_SUCCESS)
21
qWarning
(
"QMutex: failed to create semaphore, error %d"
,
r
);
22
}
23
24
QMutexPrivate::~QMutexPrivate
()
25
{
26
kern_return_t
r
= semaphore_destroy(mach_task_self(), mach_semaphore);
27
if
(
r
!= KERN_SUCCESS)
28
qWarning
(
"QMutex: failed to destroy semaphore, error %d"
,
r
);
29
}
30
31
bool
QMutexPrivate::wait
(
QDeadlineTimer
timeout
)
32
{
33
kern_return_t
r
;
34
if
(
timeout
.isForever()) {
35
do
{
36
r
= semaphore_wait(mach_semaphore);
37
}
while
(
r
== KERN_ABORTED);
38
Q_ASSERT
(
r
== KERN_SUCCESS);
39
}
else
{
40
timespec tv =
durationToTimespec
(
timeout
.remainingTimeAsDuration());
41
mach_timespec_t ts;
42
ts.tv_nsec = tv.tv_nsec;
43
ts.tv_sec = tv.tv_sec;
44
r
= semaphore_timedwait(mach_semaphore, ts);
45
}
46
return
(
r
== KERN_SUCCESS);
47
}
48
49
void
QMutexPrivate::wakeUp
() noexcept
50
{
51
semaphore_signal(mach_semaphore);
52
}
53
54
55
QT_END_NAMESPACE
QDeadlineTimer
\inmodule QtCore
Definition
qdeadlinetimer.h:23
QMutexPrivate::wait
bool wait(QDeadlineTimer timeout=QDeadlineTimer::Forever)
Definition
qmutex_mac.cpp:31
QMutexPrivate::wakeUp
void wakeUp() noexcept
Definition
qmutex_mac.cpp:49
QMutexPrivate::QMutexPrivate
QMutexPrivate()
Definition
qmutex_mac.cpp:17
QMutexPrivate::~QMutexPrivate
~QMutexPrivate()
Definition
qmutex_mac.cpp:24
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qstandardpaths_haiku.cpp:21
QT_END_NAMESPACE
Definition
qsharedpointer.cpp:1590
durationToTimespec
timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
Definition
qcore_unix_p.h:70
qWarning
#define qWarning
Definition
qlogging.h:166
qmutex.h
qmutex_p.h
r
GLboolean r
[2]
Definition
qopengles2ext.h:337
timeout
GLbitfield GLuint64 timeout
[4]
Definition
qopengles2ext.h:1029
Q_ASSERT
#define Q_ASSERT(cond)
Definition
qrandom.cpp:47
qtbase
src
corelib
thread
qmutex_mac.cpp
Generated by
1.10.0