diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2011-01-28 10:12:50 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2011-01-28 10:15:13 (GMT) |
commit | 298b54b4fa99db47d62ec37eacefb4f419b79a69 (patch) | |
tree | 376b9504ad21b927c15b5e2f98fa5b4b0a2b3bd1 /src/corelib/kernel | |
parent | b127b1036ec75c625920a6c029b64a95e3702bf9 (diff) | |
download | Qt-298b54b4fa99db47d62ec37eacefb4f419b79a69.zip Qt-298b54b4fa99db47d62ec37eacefb4f419b79a69.tar.gz Qt-298b54b4fa99db47d62ec37eacefb4f419b79a69.tar.bz2 |
Revert "Improve timer ID safety by using a serial counter per ID."
This reverts commit 121e2b39043a4ffc6583f250aebb9a3a746076c1. It was
considered too dangerous for 4.7.
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qabstracteventdispatcher.cpp | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index cc08f092..e79f87a 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -137,12 +137,6 @@ void QAbstractEventDispatcherPrivate::init() // free list). As an added protection, we use the cell to store an invalid // (negative) value that we can later check for integrity. // -// ABA prevention simply adds a value to 7 of the top 8 bits when resetting -// nextFreeTimerId. -// -// The extra code is the bucket allocation which allows us to start with a -// very small bucket size and grow as needed. -// // (continues below). int QAbstractEventDispatcherPrivate::allocateTimerId() { @@ -170,8 +164,6 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() newTimerId = prepareNewValueWithSerialNumber(timerId, b[at]); } while (!nextFreeTimerId.testAndSetRelaxed(timerId, newTimerId)); - timerId &= TimerIdMask; - timerId |= b[at] & TimerSerialMask; b[at] = -timerId; return timerId; @@ -182,13 +174,12 @@ int QAbstractEventDispatcherPrivate::allocateTimerId() // X[timerId] = nextFreeTimerId; // then we update nextFreeTimerId to the timer we've just released // +// The extra code in allocateTimerId and releaseTimerId are ABA prevention +// and bucket memory. The buckets are simply to make sure we allocate only +// the necessary number of timers. See above. +// // ABA prevention simply adds a value to 7 of the top 8 bits when resetting // nextFreeTimerId. -// -// In addition to that, we update the same 7 bits in each entry in the bucket -// as a counter. That way, a timer ID allocated and released will always be -// returned with a different ID. This reduces the chances of timers being released -// erroneously by application code. void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) { int which = timerId & TimerIdMask; @@ -196,21 +187,12 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) int at = bucketIndex(bucket, which); int *b = timerIds[bucket]; -#ifndef QT_NO_DEBUG - // debug code - Q_ASSERT_X(timerId == -b[at], "QAbstractEventDispatcher::releaseTimerId", "Timer ID was not found, fix application"); -#else - if (timerId != -b[at]) { - // release code - qWarning("Timer ID %d was not found, fix application", timerId); - return; - } -#endif + Q_ASSERT(b[at] == -timerId); int freeId, newTimerId; do { freeId = nextFreeTimerId;//.loadAcquire(); // ### FIXME Proper memory ordering semantics - b[at] = prepareNewValueWithSerialNumber(-b[at], freeId); + b[at] = freeId & TimerIdMask; newTimerId = prepareNewValueWithSerialNumber(freeId, timerId); } while (!nextFreeTimerId.testAndSetRelease(freeId, newTimerId)); |