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 <bradley.hughes@nokia.com>
bb10
Robin Burchell 2012-05-01 21:22:20 +02:00 committed by Qt by Nokia
parent c4f4be9bd1
commit a592f221c3
1 changed files with 12 additions and 0 deletions

View File

@ -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<QThread *>(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)