diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-07-21 14:42:46 +0200 |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-07-21 14:42:46 +0200 |
commit | 7b3b6b5afaaf1db1bfbfa9b56fa7b955a61344bd (patch) | |
tree | 8be0d601853d021434e03cef9a9cfd64b3708e92 /src/corelib/thread | |
parent | 070fc2f694beaa56fc191f1a3f6a1b9812f4ed35 (diff) | |
parent | 56defa4725508608a85e2813b85af3a7fcefefa0 (diff) |
Merge remote branch 'gerrit/master' into refactor
Conflicts:
examples/opengl/cube/main.cpp
examples/widgets/applicationicon/main.cpp
examples/widgets/orientation/main.cpp
src/gui/image/qicon.cpp
src/gui/image/qimage.h
src/gui/image/qpixmap.h
src/gui/image/qpixmap_mac.cpp
src/gui/kernel/qapplication.cpp
src/gui/kernel/qpalette.cpp
src/gui/kernel/qwidget.cpp
src/gui/styles/qmacstyle_mac.mm
src/gui/widgets/qmenubar.cpp
src/gui/widgets/qslider.cpp
src/opengl/qwindowsurface_gl.cpp
tests/auto/qvariant/qvariant.pro
tests/benchmarks/corelib/kernel/qobject/qobject.pro
tests/benchmarks/gui/animation/qanimation/qanimation.pro
tests/benchmarks/gui/graphicsview/qgraphicsanchorlayout/qgraphicsanchorlayout.pro
tests/benchmarks/gui/graphicsview/qgraphicsitem/qgraphicsitem.pro
tests/benchmarks/gui/graphicsview/qgraphicsscene/qgraphicsscene.pro
tests/benchmarks/gui/graphicsview/qgraphicsview/qgraphicsview.pro
tests/benchmarks/gui/graphicsview/qgraphicswidget/qgraphicswidget.pro
tests/benchmarks/gui/image/qimagereader/qimagereader.pro
tests/benchmarks/gui/itemviews/qtableview/qtableview.pro
tests/benchmarks/gui/kernel/qapplication/qapplication.pro
tests/benchmarks/gui/kernel/qwidget/qwidget.pro
tests/benchmarks/gui/painting/qpainter/qpainter.pro
tests/benchmarks/gui/painting/qtbench/qtbench.pro
tests/benchmarks/gui/painting/qtracebench/qtracebench.pro
tests/benchmarks/gui/text/qtext/qtext.pro
Change-Id: I4b911c795ecb29d73b6a7fd18819711b49478a30
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qmutex_unix.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp index 12bc7954f3..e692e19525 100644 --- a/src/corelib/thread/qmutex_unix.cpp +++ b/src/corelib/thread/qmutex_unix.cpp @@ -60,6 +60,7 @@ # include <linux/futex.h> # include <sys/syscall.h> # include <unistd.h> +# include <QtCore/qelapsedtimer.h> #endif QT_BEGIN_NAMESPACE @@ -138,16 +139,31 @@ static inline int _q_futex(volatile int *addr, int op, int val, const struct tim bool QMutexPrivate::wait(int timeout) { + struct timespec ts, *pts = 0; + QElapsedTimer timer; + if (timeout >= 0) { + ts.tv_nsec = ((timeout % 1000) * 1000) * 1000; + ts.tv_sec = (timeout / 1000); + pts = &ts; + timer.start(); + } while (contenders.fetchAndStoreAcquire(2) > 0) { - struct timespec ts, *pts = 0; - if (timeout >= 0) { - ts.tv_nsec = ((timeout % 1000) * 1000) * 1000; - ts.tv_sec = (timeout / 1000); - pts = &ts; - } int r = _q_futex(&contenders._q_value, FUTEX_WAIT, 2, pts, 0, 0); if (r != 0 && errno == ETIMEDOUT) return false; + + if (pts) { + // recalculate the timeout + qint64 xtimeout = timeout * 1000 * 1000; + xtimeout -= timer.nsecsElapsed(); + if (xtimeout < 0) { + // timer expired after we returned + return false; + } + + ts.tv_sec = timeout / Q_INT64_C(1000) / 1000 / 1000; + ts.tv_nsec = timeout % (Q_INT64_C(1000) * 1000 * 1000); + } } return true; } |