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


C++ QAtomicInt类代码示例

本文整理汇总了C++中QAtomicInt的典型用法代码示例。如果您正苦于以下问题:C++ QAtomicInt类的具体用法?C++ QAtomicInt怎么用?C++ QAtomicInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QAtomicInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: multiRef

void TestPointer::multiRef(int count)
{
	QAtomicInt											counter;
	PointerClass									*	ptrClass	=	new PointerClass(counter);
	QList<Pointer<PointerClass> >		ptrList;
	
	QVERIFY(counter.fetchAndAddOrdered(0) == 1);
	
	// Create pointer
	for(int i = 0; i < count; i++)
	{
		ptrList.append(Pointer<PointerClass>(ptrClass));
		
		QVERIFY(ptrList.last() != 0);
		QVERIFY(counter.fetchAndAddOrdered(0) == 1);
		QVERIFY(ptrList.last()->testFunc());
	}
	
	// Remove pointer (all but one)
	for(int i = count - 1; i > 0; i--)
	{
		ptrList.removeLast();
		
		QVERIFY(ptrList.last() != 0);
		QVERIFY(counter.fetchAndAddOrdered(0) == 1);
		QVERIFY(ptrList.last()->testFunc());
	}
	
	Pointer<PointerClass>	ptr(ptrList.takeLast());
	ptr	=	0;
	
	QVERIFY(ptr == 0);
	QVERIFY(counter.fetchAndAddOrdered(0) == 0);
}
开发者ID:HardcorEViruS,项目名称:MessageBus,代码行数:34,代码来源:testpointer.cpp

示例2: memcmp

ObjectId &ObjectId::init()
{
  static QAtomicInt inc = static_cast<unsigned>(QScopedPointer<SecureRandom>(SecureRandom::create())->nextInt64());

  {
    unsigned t = (unsigned) ::time(0);
    uchar *T = (uchar *) &t;
    _time[0] = T[3]; // big endian order because we use memcmp() to compare OID's
    _time[1] = T[2];
    _time[2] = T[1];
    _time[3] = T[0];
  }

  _machineAndPid = ourMachineAndPid;

  {
    const int new_inc = inc.fetchAndAddOrdered(1);
    uchar *T = (uchar *) &new_inc;
    _inc[0] = T[2];
    _inc[1] = T[1];
    _inc[2] = T[0];
  }

  return *this;
}
开发者ID:johnbolia,项目名称:schat,代码行数:25,代码来源:ObjectId.cpp

示例3: QPlatformWindow

QT_BEGIN_NAMESPACE

QFbWindow::QFbWindow(QWindow *window)
    : QPlatformWindow(window), mBackingStore(0)
{
    static QAtomicInt winIdGenerator(1);
    mWindowId = winIdGenerator.fetchAndAddRelaxed(1);

    platformScreen()->addWindow(this);
}
开发者ID:KDE,项目名称:android-qt5-qtbase,代码行数:10,代码来源:qfbwindow.cpp

示例4: single

void TestPointer::single()
{
	QAtomicInt							counter;
	Pointer<PointerClass>		ptr(new PointerClass(counter));
	
	QVERIFY(ptr != 0);
	QVERIFY(counter.fetchAndAddOrdered(0) == 1);
	QVERIFY(ptr->testFunc());
	
	ptr	=	0;
	
	QVERIFY(ptr == 0);
	QVERIFY(counter.fetchAndAddOrdered(0) == 0);
}
开发者ID:HardcorEViruS,项目名称:MessageBus,代码行数:14,代码来源:testpointer.cpp

示例5: LoggingItem

static LoggingItem *createItem(
    const char *_file, const char *_function,
    int _line, LogLevel_t _level, int _type)
{
    LoggingItem *item = new LoggingItem(
        _file, _function, _line, _level, _type);

    malloc_count.ref();

#if DEBUG_MEMORY
    int val = item_count.fetchAndAddRelaxed(1) + 1;
    if (val == 0)
        memory_time.start();
    max_count = (val > max_count) ? val : max_count;
    if (memory_time.elapsed() > 1000)
    {
        cout<<"current memory usage: "
            <<val<<" * "<<sizeof(LoggingItem)<<endl;
        cout<<"max memory usage: "
            <<max_count<<" * "<<sizeof(LoggingItem)<<endl;
        cout<<"malloc count: "<<(int)malloc_count<<endl;
        memory_time.start();
    }
#else
    item_count.ref();
#endif

    return item;
}
开发者ID:StefanRoss,项目名称:mythtv,代码行数:29,代码来源:logging.cpp

示例6: updatePeak

void TestMallocPrivate::updatePeak()
{
    if (now_usable.load() > peak_usable.load()) {
        peak_usable.fetchAndStoreOrdered(now_usable.load());
    }
    if (now_usable.load() + now_overhead.load() > peak_total.load()) {
        peak_total.fetchAndStoreOrdered(now_usable.load() + now_overhead.load());
    }
}
开发者ID:jose-g,项目名称:qt-labs-messagingframework,代码行数:9,代码来源:testmalloc.cpp

示例7: run

            void run()
            {
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(!recursiveMutex.tryLock());
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(recursiveMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(recursiveMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(1, 2));
                QVERIFY(lockCount.testAndSetRelaxed(2, 1));
                recursiveMutex.unlock();
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                recursiveMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                QTime timer;
                timer.start();
                QVERIFY(!recursiveMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() >= waitTime);
                QVERIFY(!recursiveMutex.tryLock(0));
                testsTurn.release();

                threadsTurn.acquire();
                timer.start();
                QVERIFY(recursiveMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() <= waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(recursiveMutex.tryLock(waitTime));
                QVERIFY(lockCount.testAndSetRelaxed(1, 2));
                QVERIFY(lockCount.testAndSetRelaxed(2, 1));
                recursiveMutex.unlock();
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                recursiveMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(!recursiveMutex.tryLock(0));
                QVERIFY(!recursiveMutex.tryLock(0));
                testsTurn.release();

                threadsTurn.acquire();
                timer.start();
                QVERIFY(recursiveMutex.tryLock(0));
                QVERIFY(timer.elapsed() < waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(recursiveMutex.tryLock(0));
                QVERIFY(lockCount.testAndSetRelaxed(1, 2));
                QVERIFY(lockCount.testAndSetRelaxed(2, 1));
                recursiveMutex.unlock();
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                recursiveMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:60,代码来源:tst_qmutex.cpp

示例8: stresstest

void tst_QtConcurrentIterateKernel::stresstest()
{
    const int iterations = 1000;
    const int times = 50;
    for (int i = 0; i < times; ++i) {
        counter.store(0);
        CountFor f(0, iterations);
        f.startBlocking();
        QCOMPARE(counter.load(), iterations);
    }
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:11,代码来源:tst_qtconcurrentiteratekernel.cpp

示例9: cancel

void tst_QtConcurrentIterateKernel::cancel()
{
    {
        QFuture<void> f = startThreadEngine(new SleepPrintFor(0, 40)).startAsynchronously();
        f.cancel();
        f.waitForFinished();
        QVERIFY(f.isCanceled());
         // the threads might run one iteration each before they are canceled.
        QVERIFY2(iterations.load() <= QThread::idealThreadCount(),
                 (QByteArray::number(iterations.load()) + ' ' + QByteArray::number(QThread::idealThreadCount())));
    }
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:12,代码来源:tst_qtconcurrentiteratekernel.cpp

示例10: expireClients

/// \brief Expire any clients in the delete list
void LogForwardThread::expireClients(void)
{
#ifndef NOLOGSERVER
    QMutexLocker lock(&logClientMapMutex);
    QMutexLocker lock2(&logRevClientMapMutex);
    QMutexLocker lock3(&logClientToDelMutex);

    while (!logClientToDel.isEmpty())
    {
        QString clientId = logClientToDel.takeFirst();
        logClientCount.deref();
        LOG(VB_GENERAL, LOG_INFO, QString("Expiring client %1 (#%2)")
            .arg(clientId).arg(logClientCount.fetchAndAddOrdered(0)));
        LoggerListItem *item = logClientMap.take(clientId);
        if (!item)
            continue;
        LoggerList *list = item->list;
        delete item;

        while (!list->isEmpty())
        {
            LoggerBase *logger = list->takeFirst();
            ClientList *clientList = logRevClientMap.value(logger, NULL);
            if (!clientList || clientList->size() == 1)
            {
                if (clientList)
                {
                    logRevClientMap.remove(logger);
                    delete clientList;
                }
                delete logger;
                continue;
            }

            clientList->removeAll(clientId);
        }
        delete list;
    }

    // TODO FIXME: This is not thread-safe!
    // just this daemon left
    if (logClientCount.fetchAndAddOrdered(0) == 1 &&
        m_shutdownTimer && !m_shutdownTimer->isActive())
    {
        LOG(VB_GENERAL, LOG_INFO, "Starting 5min shutdown timer");
        m_shutdownTimer->start(5*60*1000);
    }
#endif
}
开发者ID:bas-t,项目名称:mythtv,代码行数:50,代码来源:loggingserver.cpp

示例11: throttling

void tst_QtConcurrentIterateKernel::throttling()
{
    const int totalIterations = 400;
    iterations.store(0);

    threads.clear();

    ThrottleFor f(0, totalIterations);
    f.startBlocking();

    QCOMPARE(iterations.load(), totalIterations);


    QCOMPARE(threads.count(), 1);
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:15,代码来源:tst_qtconcurrentiteratekernel.cpp

示例12: QThread

TActionWorker::TActionWorker(TEpollSocket *socket, QObject *parent)
    : QThread(parent), TActionContext(), httpRequest(), clientAddr(), socketId(socket->id())
{
    workerCounter.fetchAndAddOrdered(1);
    httpRequest = socket->recvBuffer().read(INT_MAX);
    clientAddr = socket->recvBuffer().clientAddress().toString();
}
开发者ID:clawplach,项目名称:treefrog-framework,代码行数:7,代码来源:tactionworker.cpp

示例13: update

// slots
void Drive::update()
{
    if (!isOpened)
        return;
    PdoData pdoData;
    memcpy(&pdoData, ec_slave[1].inputs, sizeof(pdoData));
    //qDebug() << "statusword: " << pdoData.statusword;
    //qDebug() << "velocity actual value: " << pdoData.velocityActualValue;
    //qDebug() << "measurement velocity rpm: " << pdoData.measurementVelRpm;
    //qDebug() << "current actual filtered value: " << pdoData.currentActualValue;
    //qDebug() << "ue: " << pdoData.ue;
    //qDebug() << "up: " << pdoData.up;

    emit rpmChanged(pdoData.velocityActualValue);
    //emit currentChanged(pdoData.currentActualValue);

    bool ok = !EcatError;
    while (EcatError)
        qDebug("%s", ec_elist2string());

    //emit stateChanged(ok);
    ok = true;
//
//    qDebug("Slave State=0x%2.2x StatusCode=0x%4.4x : %s",
//           ec_slave[1].state, ec_slave[1].ALstatuscode, ec_ALstatuscode2string(ec_slave[1].ALstatuscode));

    if (globalErrorFlag.fetchAndStoreRelaxed(GLOBAL_OK) == GLOBAL_ERROR) {
        qDebug("ERROR from iothread");
        isWorking = false;
        emit error();
    }
}
开发者ID:toxa-svr,项目名称:ServoDrive,代码行数:33,代码来源:Drive.cpp

示例14: takeObject

   /// Take an object and prevent timer resource leaks when the object is about
   /// to become threadless.
   void takeObject(QObject *obj) {
      // Work around to prevent
      // QBasicTimer::stop: Failed. Possibly trying to stop from a different thread
      static constexpr char kRegistered[] = "__ThreadRegistered";
      static constexpr char kMoved[] = "__Moved";
      if (!obj->property(kRegistered).isValid()) {
         QObject::connect(this, &Thread::finished, obj, [this, obj]{
            if (!inDestructor.load() || obj->thread() != this)
               return;
            // The object is about to become threadless
            Q_ASSERT(obj->thread() == QThread::currentThread());
            obj->setProperty(kMoved, true);
            obj->moveToThread(this->thread());
         }, Qt::DirectConnection);
         QObject::connect(this, &QObject::destroyed, obj, [obj]{
            if (!obj->thread()) {
               obj->moveToThread(QThread::currentThread());
               obj->setProperty(kRegistered, {});
            }
            else if (obj->thread() == QThread::currentThread() && obj->property(kMoved).isValid()) {
               obj->setProperty(kMoved, {});
               QCoreApplication::sendPostedEvents(obj, QEvent::MetaCall);
            }
            else if (obj->thread()->eventDispatcher())
               QTimer::singleShot(0, obj, [obj]{ obj->setProperty(kRegistered, {}); });
         }, Qt::DirectConnection);

         obj->setProperty(kRegistered, true);
      }
      obj->moveToThread(this);
   }
开发者ID:adolby,项目名称:Kryvos,代码行数:33,代码来源:Thread.hpp

示例15:

ULONG		CDeckLinkGLWidget::AddRef ()
{
	int		oldValue;
	
	oldValue = refCount.fetchAndAddAcquire(1);
	return (ULONG)(oldValue + 1);
}
开发者ID:wolfg1969,项目名称:Blackmagic-Decklink-SDK-Archive,代码行数:7,代码来源:SignalGenerator.cpp


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