本文整理汇总了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);
}
示例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;
}
示例3: QPlatformWindow
QT_BEGIN_NAMESPACE
QFbWindow::QFbWindow(QWindow *window)
: QPlatformWindow(window), mBackingStore(0)
{
static QAtomicInt winIdGenerator(1);
mWindowId = winIdGenerator.fetchAndAddRelaxed(1);
platformScreen()->addWindow(this);
}
示例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);
}
示例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;
}
示例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());
}
}
示例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();
}
示例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);
}
}
示例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())));
}
}
示例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
}
示例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);
}
示例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();
}
示例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();
}
}
示例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);
}
示例15:
ULONG CDeckLinkGLWidget::AddRef ()
{
int oldValue;
oldValue = refCount.fetchAndAddAcquire(1);
return (ULONG)(oldValue + 1);
}