summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex_unix.cpp
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-07-20 08:21:16 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-07-20 08:21:16 (GMT)
commit75a891109a9fc7006ee241616a85290334b17012 (patch)
tree681cce019c231932e15603b1bc6e3cb4f75db9d8 /src/corelib/thread/qmutex_unix.cpp
parent1541c27f4eeebb73434d77f866c99c937cf6544d (diff)
parent075b0f744363842ed4179c644d933d461389544f (diff)
downloadQt-75a891109a9fc7006ee241616a85290334b17012.zip
Qt-75a891109a9fc7006ee241616a85290334b17012.tar.gz
Qt-75a891109a9fc7006ee241616a85290334b17012.tar.bz2
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qt-water-team
* 'master' of git://scm.dev.nokia.troll.no/qt/qt-water-team: (34 commits) Remove testing for Hide of mainwindow. Fix accessibility test for QWS. Fixes leaking X11 SyncCounter when widgets get open/destroyed Fix the timeout calculation for futexes in QMutex. Fix test for win and mac. namespace fix fix build get rid of unwanted dependencies and unused header includes sync qws_dataDir() with coreapp's internal qws_dataDir() Add constants to QAccessible::Event enum. Call QAccessible::updateAccessibility when setText is called on QLabel Added Solaris build fix to the changes file. Documentation fix. Fix autotest for accessible tables. make argument quoting code on windows less arcane fix argument quoting on windows Style cleanup - space after flow control keywords. Add IAccessible2 table2 implementation. Fix potential crash when clicking in a text edit Compensate for different rounding rule in CG engine ...
Diffstat (limited to 'src/corelib/thread/qmutex_unix.cpp')
-rw-r--r--src/corelib/thread/qmutex_unix.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp
index 12bc795..e692e19 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;
}