42 #include "qplatformdefs.h" 52 #if defined(Q_OS_VXWORKS) && defined(wakeup) 57 # include <mach/mach.h> 58 # include <mach/task.h> 59 #elif defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) 60 # include <linux/futex.h> 61 # include <sys/syscall.h> 63 # include <QtCore/qelapsedtimer.h> 68 #if !defined(Q_OS_LINUX) || defined(QT_LINUXBASE) 69 static void report_error(
int code,
const char *where,
const char *what)
78 :
QMutexData(mode), maximumSpinTime(MaximumSpinTimeThreshold), averageWaitTime(0),
owner(0), count(0)
80 #if !defined(Q_OS_LINUX) || defined(QT_LINUXBASE) 82 report_error(pthread_mutex_init(&mutex, NULL),
"QMutex",
"mutex init");
83 report_error(pthread_cond_init(&cond, NULL),
"QMutex",
"cv init");
89 #if !defined(Q_OS_LINUX) || defined(QT_LINUXBASE) 90 report_error(pthread_cond_destroy(&cond),
"QMutex",
"cv destroy");
91 report_error(pthread_mutex_destroy(&mutex),
"QMutex",
"mutex destroy");
95 #if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) 97 static inline int _q_futex(
volatile int *addr,
int op,
int val,
const struct timespec *timeout,
int *addr2,
int val2)
99 return syscall(SYS_futex, addr, op, val, timeout, addr2, val2);
104 struct timespec ts, *pts = 0;
107 ts.tv_nsec = ((timeout % 1000) * 1000) * 1000;
108 ts.tv_sec = (timeout / 1000);
114 if (r != 0 &&
errno == ETIMEDOUT)
119 qint64 xtimeout = timeout * 1000 * 1000;
126 ts.tv_sec = xtimeout /
Q_INT64_C(1000) / 1000 / 1000;
127 ts.tv_nsec = xtimeout % (
Q_INT64_C(1000) * 1000 * 1000);
139 #else // !Q_OS_LINUX || QT_LINUXBASE 147 report_error(pthread_mutex_lock(&mutex),
"QMutex::lock",
"mutex lock");
151 errorCode = pthread_cond_wait(&cond, &mutex);
154 gettimeofday(&tv, 0);
157 ti.tv_nsec = (tv.tv_usec + (timeout % 1000) * 1000) * 1000;
158 ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000);
159 ti.tv_nsec %= 1000000000;
161 errorCode = pthread_cond_timedwait(&cond, &mutex, &ti);
164 if (errorCode == ETIMEDOUT) {
173 report_error(pthread_mutex_unlock(&mutex),
"QMutex::lock",
"mutex unlock");
175 return errorCode == 0;
180 report_error(pthread_mutex_lock(&mutex),
"QMutex::unlock",
"mutex lock");
182 report_error(pthread_cond_signal(&cond),
"QMutex::unlock",
"cv signal");
183 report_error(pthread_mutex_unlock(&mutex),
"QMutex::unlock",
"mutex unlock");
186 #endif // !Q_OS_LINUX || QT_LINUXBASE 190 #endif // QT_NO_THREAD
QString qt_error_string(int errorCode)
#define QT_END_NAMESPACE
This macro expands to.
bool wait(int timeout=-1)
The QElapsedTimer class provides a fast way to calculate elapsed times.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool deref()
Atomically decrements the value of this QAtomicInt.
Q_CORE_EXPORT void qWarning(const char *,...)
static int _q_futex(volatile int *addr, int op, int val, const struct timespec *timeout, int *addr2, int val2)
qint64 nsecsElapsed() const
Returns the number of nanoseconds since this QElapsedTimer was last started.
int fetchAndAddAcquire(int valueToAdd)
Atomic fetch-and-add.
static void report_error(int code, const char *where, const char *what)
int fetchAndStoreAcquire(int newValue)
Atomic fetch-and-store.
QMutexPrivate(QMutex::RecursionMode mode)
#define qPrintable(string)
void start()
Starts this timer.
int fetchAndStoreRelease(int newValue)
Atomic fetch-and-store.