From 77e8ff66f0f9d798b386cf65bc5aa58a5738be9a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 23 Aug 2013 13:01:18 -0700 Subject: Move the creation of QElapsedTimer out of the inner function in QMutex Makes it possible for QElapsedTimer to be non-POD. Change-Id: I5ffc59c7a93c187a4a814e6959f8383fa8d4cc44 Reviewed-by: Robin Burchell --- src/corelib/thread/qmutex_linux.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'src/corelib/thread/qmutex_linux.cpp') diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 24d89030d1..18aedfbf75 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -54,21 +54,6 @@ #include #include -#if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L -// C++11 mode -# include - -static void checkElapsedTimerIsTrivial() -{ - Q_STATIC_ASSERT(std::has_trivial_default_constructor::value); -} - -#else -static void checkElapsedTimerIsTrivial() -{ -} -#endif - #ifndef QT_LINUX_FUTEX # error "Qt build is broken: qmutex_linux.cpp is being built but futex support is not wanted" #endif @@ -175,7 +160,7 @@ static inline QMutexData *dummyFutexValue() } template static inline -bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = -1) Q_DECL_NOTHROW +bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = 0) Q_DECL_NOTHROW { if (!IsTimed) timeout = -1; @@ -185,12 +170,9 @@ bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = - return false; struct timespec ts, *pts = 0; - QElapsedTimer elapsedTimer; - checkElapsedTimerIsTrivial(); if (IsTimed && timeout > 0) { ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000 * 1000; - elapsedTimer.start(); } // the mutex is locked already, set a bit indicating we're waiting @@ -198,7 +180,7 @@ bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = - if (IsTimed && pts == &ts) { // recalculate the timeout qint64 xtimeout = qint64(timeout) * 1000 * 1000; - xtimeout -= elapsedTimer.nsecsElapsed(); + xtimeout -= elapsedTimer->nsecsElapsed(); if (xtimeout <= 0) { // timer expired after we returned return false; @@ -232,7 +214,9 @@ void QBasicMutex::lockInternal() Q_DECL_NOTHROW bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW { Q_ASSERT(!isRecursive()); - return lockInternal_helper(d_ptr, timeout); + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + return lockInternal_helper(d_ptr, timeout, &elapsedTimer); } void QBasicMutex::unlockInternal() Q_DECL_NOTHROW -- cgit v1.2.3