本文整理汇总了C++中QBasicAtomicInt::testAndSetRelease方法的典型用法代码示例。如果您正苦于以下问题:C++ QBasicAtomicInt::testAndSetRelease方法的具体用法?C++ QBasicAtomicInt::testAndSetRelease怎么用?C++ QBasicAtomicInt::testAndSetRelease使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBasicAtomicInt
的用法示例。
在下文中一共展示了QBasicAtomicInt::testAndSetRelease方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: releaseTimerId
void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId)
{
int which = timerId & 0x00ffffff;
int bucket = bucketOffset(which);
int at = bucketIndex(bucket, which);
int *b = timerIds[bucket];
int freeId, newTimerId;
do {
freeId = nextFreeTimerId;
b[at] = freeId & 0x00ffffff;
newTimerId = prepareNewValueWithSerialNumber(freeId, timerId);
} while (!nextFreeTimerId.testAndSetRelease(freeId, newTimerId));
}
示例2: releaseTimerId
// Releasing a timer ID requires putting the current ID back in the vector;
// we do it by setting:
// 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.
void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId)
{
int which = timerId & TimerIdMask;
int bucket = bucketOffset(which);
int at = bucketIndex(bucket, which);
int *b = timerIds[bucket];
Q_ASSERT_X(timerId == -b[at], "QAbstractEventDispatcher::releaseTimerId",
"Internal error: timer ID not found");
int freeId, newTimerId;
do {
freeId = nextFreeTimerId;//.loadAcquire(); // ### FIXME Proper memory ordering semantics
b[at] = freeId & TimerIdMask;
newTimerId = prepareNewValueWithSerialNumber(freeId, timerId);
} while (!nextFreeTimerId.testAndSetRelease(freeId, newTimerId));
}