From a592f221c31c7eafedfa7fba1e19281073c249dd Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 1 May 2012 21:22:20 +0200 Subject: Guard some pthread API with the appropriate POSIX check, or Android. Android does not support some parts of POSIX. It's also unfortunately not POSIX-compliant, meaning we need to guard things like pthread_cancel. Change-Id: I2979eb5579c822f4f5ba27bcc29e118b908e8bdc Reviewed-by: Bradley T. Hughes --- src/corelib/thread/qthread_unix.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index a47115cfac..b3040f3dee 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -272,7 +272,9 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data) void *QThreadPrivate::start(void *arg) { +#if !defined(Q_OS_LINUX_ANDROID) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); +#endif pthread_cleanup_push(QThreadPrivate::finish, arg); QThread *thr = reinterpret_cast(arg); @@ -314,8 +316,10 @@ void *QThreadPrivate::start(void *arg) #endif emit thr->started(); +#if !defined(Q_OS_LINUX_ANDROID) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_testcancel(); +#endif thr->run(); pthread_cleanup_pop(1); @@ -617,7 +621,9 @@ void QThread::start(Priority priority) if (code == EPERM) { // caller does not have permission to set the scheduling // parameters/policy +#if defined(QT_HAS_THREAD_PRIORITY_SCHEDULING) pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); +#endif code = pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); } @@ -635,6 +641,7 @@ void QThread::start(Priority priority) void QThread::terminate() { +#if !defined(Q_OS_LINUX_ANDROID) Q_D(QThread); QMutexLocker locker(&d->mutex); @@ -648,6 +655,7 @@ void QThread::terminate() } else { d->terminated = true; } +#endif } bool QThread::wait(unsigned long time) @@ -677,9 +685,13 @@ void QThread::setTerminationEnabled(bool enabled) "Current thread was not started with QThread."); Q_UNUSED(thr) +#if defined(Q_OS_LINUX_ANDROID) + Q_UNUSED(enabled); +#else pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, NULL); if (enabled) pthread_testcancel(); +#endif } void QThread::setPriority(Priority priority) -- cgit v1.2.3