本文整理汇总了C++中QBasicAtomicInt::testAndSetRelaxed方法的典型用法代码示例。如果您正苦于以下问题:C++ QBasicAtomicInt::testAndSetRelaxed方法的具体用法?C++ QBasicAtomicInt::testAndSetRelaxed怎么用?C++ QBasicAtomicInt::testAndSetRelaxed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBasicAtomicInt
的用法示例。
在下文中一共展示了QBasicAtomicInt::testAndSetRelaxed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: allocateTimerId
// Timer IDs are implemented using a free-list;
// there's a vector initialized with:
// X[i] = i + 1
// and nextFreeTimerId starts with 1.
//
// Allocating a timer ID involves taking the ID from
// X[nextFreeTimerId]
// updating nextFreeTimerId to this value and returning the old value
//
// When the timer ID is allocated, its cell in the vector is unused (it's a
// free list). As an added protection, we use the cell to store an invalid
// (negative) value that we can later check for integrity.
//
// (continues below).
int QAbstractEventDispatcherPrivate::allocateTimerId()
{
int timerId, newTimerId;
int at, *b;
do {
timerId = nextFreeTimerId; //.loadAcquire(); // ### FIXME Proper memory ordering semantics
// which bucket are we looking in?
int which = timerId & TimerIdMask;
int bucket = bucketOffset(which);
at = bucketIndex(bucket, which);
b = timerIds[bucket];
if (!b) {
// allocate a new bucket
b = allocateBucket(bucket);
if (!timerIds[bucket].testAndSetRelease(0, b)) {
// another thread won the race to allocate the bucket
delete [] b;
b = timerIds[bucket];
}
}
newTimerId = prepareNewValueWithSerialNumber(timerId, b[at]);
} while (!nextFreeTimerId.testAndSetRelaxed(timerId, newTimerId));
b[at] = -timerId;
return timerId;
}
示例2: allocateTimerId
int QAbstractEventDispatcherPrivate::allocateTimerId()
{
int timerId, newTimerId;
do {
timerId = nextFreeTimerId;
// which bucket are we looking in?
int which = timerId & 0x00ffffff;
int bucket = bucketOffset(which);
int at = bucketIndex(bucket, which);
int *b = timerIds[bucket];
if (!b) {
// allocate a new bucket
b = allocateBucket(bucket);
if (!timerIds[bucket].testAndSetRelease(0, b)) {
// another thread won the race to allocate the bucket
delete [] b;
b = timerIds[bucket];
}
}
newTimerId = b[at];
} while (!nextFreeTimerId.testAndSetRelaxed(timerId, newTimerId));
return timerId;
}
示例3: qt_ignore_sigpipe
// Lifted from Qt. I don't think they would mind. ;)
// Re-lift again from Qt whenever a proper replacement for pthread_once appears
static void qt_ignore_sigpipe()
{
static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0);
if (atom.testAndSetRelaxed(0, 1)) {
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &noaction, 0);
}
}
示例4: qt_ignore_sigpipe
static void qt_ignore_sigpipe()
{
#ifndef Q_NO_POSIX_SIGNALS
// Set to ignore SIGPIPE once only.
static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0);
if (atom.testAndSetRelaxed(0, 1)) {
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
::sigaction(SIGPIPE, &noaction, 0);
}
#else
// Posix signals are not supported by the underlying platform
// so we don't need to ignore sigpipe signal explicitly
#endif
}
示例5: setCurrentValueForProgress
void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
{
Q_Q(QVariantAnimation);
const qreal startProgress = currentInterval.start.first;
const qreal endProgress = currentInterval.end.first;
const qreal localProgress = (progress - startProgress) / (endProgress - startProgress);
QVariant ret = q->interpolated(currentInterval.start.second,
currentInterval.end.second,
localProgress);
qSwap(currentValue, ret);
q->updateCurrentValue(currentValue);
static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0);
if (!changedSignalIndex) {
//we keep the mask so that we emit valueChanged only when needed (for performance reasons)
changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
}
if (isSignalConnected(changedSignalIndex) && currentValue != ret) {
//the value has changed
emit q->valueChanged(currentValue);
}
}