diff options
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qatomic.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qbasicatomic.h | 6 | ||||
-rw-r--r-- | src/corelib/thread/qexception.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qfuture.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface.h | 3 | ||||
-rw-r--r-- | src/corelib/thread/qfuturesynchronizer.h | 3 | ||||
-rw-r--r-- | src/corelib/thread/qfuturewatcher.h | 3 | ||||
-rw-r--r-- | src/corelib/thread/qgenericatomic.h | 5 | ||||
-rw-r--r-- | src/corelib/thread/qmutex.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qmutex_p.h | 9 | ||||
-rw-r--r-- | src/corelib/thread/qmutex_unix.cpp | 11 | ||||
-rw-r--r-- | src/corelib/thread/qoldbasicatomic.h | 5 | ||||
-rw-r--r-- | src/corelib/thread/qreadwritelock.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qresultstore.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qrunnable.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qsemaphore.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qthread.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 23 | ||||
-rw-r--r-- | src/corelib/thread/qthreadpool.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthreadstorage.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qwaitcondition.h | 4 | ||||
-rw-r--r-- | src/corelib/thread/qwaitcondition_unix.cpp | 46 |
22 files changed, 73 insertions, 79 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 06cee4894e..1ccaecc135 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -46,8 +46,6 @@ #include <QtCore/qbasicatomic.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -220,6 +218,4 @@ inline void qAtomicDetach(T *&d) } QT_END_NAMESPACE -QT_END_HEADER - #endif // QATOMIC_H diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 70b69827c2..5c5d2637b3 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -101,15 +101,11 @@ // Only include if the implementation has been ported to QAtomicOps #ifndef QOLDBASICATOMIC_H -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #if 0 // silence syncqt warnings QT_END_NAMESPACE -QT_END_HEADER - #pragma qt_no_master_include #pragma qt_sync_stop_processing #endif @@ -271,8 +267,6 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QOLDBASICATOMIC_H #endif // QBASICATOMIC_H diff --git a/src/corelib/thread/qexception.h b/src/corelib/thread/qexception.h index fa944ce69d..accf0fc7b4 100644 --- a/src/corelib/thread/qexception.h +++ b/src/corelib/thread/qexception.h @@ -53,7 +53,6 @@ # include <exception> #endif -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -116,7 +115,6 @@ public: #endif // QT_NO_EXCEPTIONS QT_END_NAMESPACE -QT_END_HEADER #endif // QT_NO_QFUTURE diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index d9c4f1af77..8071e80d1b 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -49,7 +49,6 @@ #include <QtCore/qfutureinterface.h> #include <QtCore/qstring.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -269,7 +268,6 @@ QFuture<void> qToVoidFuture(const QFuture<T> &future) } QT_END_NAMESPACE -QT_END_HEADER #endif // QT_NO_QFUTURE diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index 6ab1409f55..d2d58a9332 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -50,7 +50,6 @@ #include <QtCore/qexception.h> #include <QtCore/qresultstore.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -310,8 +309,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_QFUTURE #endif // QFUTUREINTERFACE_H diff --git a/src/corelib/thread/qfuturesynchronizer.h b/src/corelib/thread/qfuturesynchronizer.h index 60960f7711..426bb42b0d 100644 --- a/src/corelib/thread/qfuturesynchronizer.h +++ b/src/corelib/thread/qfuturesynchronizer.h @@ -46,7 +46,6 @@ #ifndef QT_NO_QFUTURE -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -113,8 +112,6 @@ protected: }; QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_QFUTURE #endif // QFUTURESYNCHRONIZER_H diff --git a/src/corelib/thread/qfuturewatcher.h b/src/corelib/thread/qfuturewatcher.h index d41b6139b6..c78ed7a83b 100644 --- a/src/corelib/thread/qfuturewatcher.h +++ b/src/corelib/thread/qfuturewatcher.h @@ -48,7 +48,6 @@ #include <QtCore/qobject.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -215,8 +214,6 @@ Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_fut } QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_QFUTURE #endif // QFUTUREWATCHER_H diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index 90f0223ccf..a8d626a43f 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -44,14 +44,11 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE #if 0 // silence syncqt warnings QT_END_NAMESPACE -QT_END_HEADER - #pragma qt_sync_stop_processing #endif @@ -241,6 +238,4 @@ template <typename BaseClass> struct QGenericAtomicOps #undef always_inline QT_END_NAMESPACE -QT_END_HEADER - #endif // QGENERICATOMIC_H diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 94bcdd1750..0bca0def22 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -46,8 +46,6 @@ #include <QtCore/qatomic.h> #include <new> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -211,6 +209,4 @@ typedef QMutex QBasicMutex; QT_END_NAMESPACE -QT_END_HEADER - #endif // QMUTEX_H diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h index 1b8bcd6b3a..bec2d934c1 100644 --- a/src/corelib/thread/qmutex_p.h +++ b/src/corelib/thread/qmutex_p.h @@ -70,6 +70,8 @@ # define QT_LINUX_FUTEX #endif +struct timespec; + QT_BEGIN_NAMESPACE class QMutexData @@ -137,6 +139,13 @@ public: #endif //QT_LINUX_FUTEX +#ifdef Q_OS_UNIX +// helper functions for qmutex_unix.cpp and qwaitcondition_unix.cpp +// they are in qwaitcondition_unix.cpp actually +void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where); +void qt_abstime_for_timeout(struct timespec *ts, int timeout); +#endif + QT_END_NAMESPACE #endif // QMUTEX_P_H diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp index ef030cb49a..2f8c2e1dc8 100644 --- a/src/corelib/thread/qmutex_unix.cpp +++ b/src/corelib/thread/qmutex_unix.cpp @@ -42,11 +42,14 @@ #include "qplatformdefs.h" #include "qmutex.h" #include "qstring.h" +#include "qelapsedtimer.h" #ifndef QT_NO_THREAD #include "qatomic.h" #include "qmutex_p.h" #include <errno.h> +#include <sys/time.h> +#include <time.h> #if defined(Q_OS_VXWORKS) && defined(wakeup) #undef wakeup @@ -64,7 +67,7 @@ QMutexPrivate::QMutexPrivate() : wakeup(false) { report_error(pthread_mutex_init(&mutex, NULL), "QMutex", "mutex init"); - report_error(pthread_cond_init(&cond, NULL), "QMutex", "cv init"); + qt_initialize_pthread_cond(&cond, "QMutex"); } QMutexPrivate::~QMutexPrivate() @@ -81,12 +84,8 @@ bool QMutexPrivate::wait(int timeout) if (timeout < 0) { errorCode = pthread_cond_wait(&cond, &mutex); } else { - struct timeval tv; - gettimeofday(&tv, 0); timespec ti; - ti.tv_nsec = (tv.tv_usec + (timeout % 1000) * 1000) * 1000; - ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; + qt_abstime_for_timeout(&ti, timeout); errorCode = pthread_cond_timedwait(&cond, &mutex, &ti); } if (errorCode) { diff --git a/src/corelib/thread/qoldbasicatomic.h b/src/corelib/thread/qoldbasicatomic.h index 15785e2232..220dade850 100644 --- a/src/corelib/thread/qoldbasicatomic.h +++ b/src/corelib/thread/qoldbasicatomic.h @@ -44,16 +44,12 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #if 0 // silence syncqt warnings QT_END_NAMESPACE -QT_END_HEADER - #pragma qt_no_master_include #pragma qt_sync_stop_processing #endif @@ -142,6 +138,5 @@ public: #define Q_BASIC_ATOMIC_INITIALIZER(a) { (a) } QT_END_NAMESPACE -QT_END_HEADER #endif // QOLDBASICATOMIC_H diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h index 8217d4eacd..6815878ec5 100644 --- a/src/corelib/thread/qreadwritelock.h +++ b/src/corelib/thread/qreadwritelock.h @@ -44,8 +44,6 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -231,6 +229,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QREADWRITELOCK_H diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h index 8c1787bc11..c14146656a 100644 --- a/src/corelib/thread/qresultstore.h +++ b/src/corelib/thread/qresultstore.h @@ -49,7 +49,6 @@ #include <QtCore/qmap.h> #include <QtCore/qdebug.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -234,7 +233,6 @@ public: #endif //Q_QDOC QT_END_NAMESPACE -QT_END_HEADER #endif // QT_NO_QFUTURE diff --git a/src/corelib/thread/qrunnable.h b/src/corelib/thread/qrunnable.h index ba03519872..a6cc095258 100644 --- a/src/corelib/thread/qrunnable.h +++ b/src/corelib/thread/qrunnable.h @@ -44,7 +44,6 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -67,6 +66,5 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h index b47588ce62..40200151b0 100644 --- a/src/corelib/thread/qsemaphore.h +++ b/src/corelib/thread/qsemaphore.h @@ -44,8 +44,6 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -77,6 +75,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSEMAPHORE_H diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index c6c6167da7..19c0f82d86 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -46,8 +46,6 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -164,6 +162,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTHREAD_H diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 8abf1d06ef..f7397dd8d4 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -415,6 +415,13 @@ int QThread::idealThreadCount() Q_DECL_NOTHROW // IRIX cores = (int)sysconf(_SC_NPROC_ONLN); #elif defined(Q_OS_INTEGRITY) +#if (__INTEGRITY_MAJOR_VERSION >= 10) + // Integrity V10+ does support multicore CPUs + Value processorCount; + if (GetProcessorCount(CurrentTask(), &processorCount) == 0) + cores = processorCount; + else +#endif // as of aug 2008 Integrity only supports one single core CPU cores = 1; #elif defined(Q_OS_VXWORKS) @@ -488,8 +495,20 @@ static bool calculateUnixPriority(int priority, int *sched_policy, int *sched_pr #endif const int highestPriority = QThread::TimeCriticalPriority; - int prio_min = sched_get_priority_min(*sched_policy); - int prio_max = sched_get_priority_max(*sched_policy); + int prio_min; + int prio_max; +#if defined(Q_OS_VXWORKS) && defined(VXWORKS_DKM) + // for other scheduling policies than SCHED_RR or SCHED_FIFO + prio_min = SCHED_FIFO_LOW_PRI; + prio_max = SCHED_FIFO_HIGH_PRI; + + if ((*sched_policy == SCHED_RR) || (*sched_policy == SCHED_FIFO)) +#endif + { + prio_min = sched_get_priority_min(*sched_policy); + prio_max = sched_get_priority_max(*sched_policy); + } + if (prio_min == -1 || prio_max == -1) return false; diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h index bc572fc8e8..ffc16dedbe 100644 --- a/src/corelib/thread/qthreadpool.h +++ b/src/corelib/thread/qthreadpool.h @@ -49,7 +49,6 @@ #ifndef QT_NO_THREAD -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -87,7 +86,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QT_NO_THREAD diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h index c98d181c1f..86285de84f 100644 --- a/src/corelib/thread/qthreadstorage.h +++ b/src/corelib/thread/qthreadstorage.h @@ -46,8 +46,6 @@ #ifndef QT_NO_THREAD -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -156,8 +154,6 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_THREAD #endif // QTHREADSTORAGE_H diff --git a/src/corelib/thread/qwaitcondition.h b/src/corelib/thread/qwaitcondition.h index e8f51dad54..1468951373 100644 --- a/src/corelib/thread/qwaitcondition.h +++ b/src/corelib/thread/qwaitcondition.h @@ -46,8 +46,6 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWAITCONDITION_H diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index ab4e7872fb..9b5c8d000d 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -45,11 +45,15 @@ #include "qreadwritelock.h" #include "qatomic.h" #include "qstring.h" +#include "qelapsedtimer.h" +#include "private/qcore_unix_p.h" #include "qmutex_p.h" #include "qreadwritelock_p.h" #include <errno.h> +#include <sys/time.h> +#include <time.h> #ifndef QT_NO_THREAD @@ -61,6 +65,38 @@ static void report_error(int code, const char *where, const char *what) qWarning("%s: %s failure: %s", where, what, qPrintable(qt_error_string(code))); } +void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where) +{ + pthread_condattr_t condattr; + + pthread_condattr_init(&condattr); +#if !defined(Q_OS_MAC) && (_POSIX_MONOTONIC_CLOCK-0 >= 0) + if (QElapsedTimer::clockType() == QElapsedTimer::MonotonicClock) + pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); +#endif + report_error(pthread_cond_init(cond, &condattr), where, "cv init"); + pthread_condattr_destroy(&condattr); +} + +void qt_abstime_for_timeout(timespec *ts, int timeout) +{ +#ifdef Q_OS_MAC + // on Mac, qt_gettime() (on qelapsedtimer_mac.cpp) returns ticks related to the Mach absolute time + // that doesn't work with pthread + // Mac also doesn't have clock_gettime + struct timeval tv; + gettimeofday(&tv, 0); + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec * 1000; +#else + *ts = qt_gettime(); +#endif + + ts->tv_sec += timeout / 1000; + ts->tv_nsec += timeout % 1000 * Q_UINT64_C(1000) * 1000; + normalizedTimespec(*ts); +} + class QWaitConditionPrivate { public: pthread_mutex_t mutex; @@ -73,14 +109,8 @@ public: int code; forever { if (time != ULONG_MAX) { - struct timeval tv; - gettimeofday(&tv, 0); - timespec ti; - ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; - ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; - + qt_abstime_for_timeout(&ti, time); code = pthread_cond_timedwait(&cond, &mutex, &ti); } else { code = pthread_cond_wait(&cond, &mutex); @@ -114,7 +144,7 @@ QWaitCondition::QWaitCondition() { d = new QWaitConditionPrivate; report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init"); - report_error(pthread_cond_init(&d->cond, NULL), "QWaitCondition", "cv init"); + qt_initialize_pthread_cond(&d->cond, "QWaitCondition"); d->waiters = d->wakeups = 0; } |