当前位置: 首页>>代码示例>>C++>>正文


C++ QBasicAtomicInt::testAndSetRelaxed方法代码示例

本文整理汇总了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;
}
开发者ID:tsuibin,项目名称:emscripten-qt,代码行数:44,代码来源:qabstracteventdispatcher.cpp

示例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;
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:27,代码来源:qabstracteventdispatcher.cpp

示例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);
    }
}
开发者ID:Swordfish90,项目名称:qmltermwidget,代码行数:12,代码来源:kptydevice.cpp

示例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
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例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);
    }
}
开发者ID:12307,项目名称:VLC-for-VS2010,代码行数:23,代码来源:qvariantanimation.cpp


注:本文中的QBasicAtomicInt::testAndSetRelaxed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。