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
16
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
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
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
49void QMutexPrivate::wakeUp() noexcept
50{
51 semaphore_signal(mach_semaphore);
52}
53
54
\inmodule QtCore
bool wait(QDeadlineTimer timeout=QDeadlineTimer::Forever)
void wakeUp() noexcept
Combined button and popup list for selecting options.
timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
#define qWarning
Definition qlogging.h:166
GLboolean r
[2]
GLbitfield GLuint64 timeout
[4]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47