本文整理汇总了C++中QAtomicInt::deref方法的典型用法代码示例。如果您正苦于以下问题:C++ QAtomicInt::deref方法的具体用法?C++ QAtomicInt::deref怎么用?C++ QAtomicInt::deref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAtomicInt
的用法示例。
在下文中一共展示了QAtomicInt::deref方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run()
{
testsTurn.release();
threadsTurn.acquire();
QVERIFY(!readWriteLock.tryLockForRead());
testsTurn.release();
threadsTurn.acquire();
QVERIFY(readWriteLock.tryLockForRead());
lockCount.ref();
QVERIFY(readWriteLock.tryLockForRead());
lockCount.ref();
lockCount.deref();
readWriteLock.unlock();
lockCount.deref();
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
QTime timer;
timer.start();
QVERIFY(!readWriteLock.tryLockForRead(1000));
QVERIFY(timer.elapsed() >= 1000);
testsTurn.release();
threadsTurn.acquire();
timer.start();
QVERIFY(readWriteLock.tryLockForRead(1000));
QVERIFY(timer.elapsed() <= 1000);
lockCount.ref();
QVERIFY(readWriteLock.tryLockForRead(1000));
lockCount.ref();
lockCount.deref();
readWriteLock.unlock();
lockCount.deref();
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
}
示例2: deleteItem
static void deleteItem(LoggingItem *item)
{
if (!item)
return;
if (!item->refcount.deref())
{
if (item->threadName)
free(item->threadName);
item_count.deref();
delete item;
}
}
示例3: sendConnectionEvent
void QEglFSX11Hooks::platformDestroy()
{
running.deref();
sendConnectionEvent(XCB_ATOM_NONE);
m_eventReader->wait();
delete m_eventReader;
m_eventReader = 0;
XCloseDisplay(m_display);
m_display = 0;
m_connection = 0;
}
示例4: 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
}
示例5: subRef
bool subRef() { return (ref.deref()); }
示例6: tryWriteLock
void tst_QReadWriteLock::tryWriteLock()
{
{
QReadWriteLock rwlock;
QVERIFY(rwlock.tryLockForWrite());
rwlock.unlock();
QVERIFY(rwlock.tryLockForWrite());
rwlock.unlock();
rwlock.lockForWrite();
QVERIFY(!rwlock.tryLockForWrite());
QVERIFY(!rwlock.tryLockForWrite());
rwlock.unlock();
rwlock.lockForRead();
QVERIFY(!rwlock.tryLockForWrite());
rwlock.unlock();
}
{
QReadWriteLock rwlock(QReadWriteLock::Recursive);
QVERIFY(rwlock.tryLockForWrite());
rwlock.unlock();
QVERIFY(rwlock.tryLockForWrite());
rwlock.unlock();
rwlock.lockForWrite();
QVERIFY(rwlock.tryLockForWrite());
QVERIFY(rwlock.tryLockForWrite());
rwlock.unlock();
rwlock.unlock();
rwlock.unlock();
rwlock.lockForRead();
QVERIFY(!rwlock.tryLockForWrite());
rwlock.unlock();
}
// functionality test
{
class Thread : public QThread
{
public:
Thread() : failureCount(0) { }
void run()
{
testsTurn.release();
threadsTurn.acquire();
if (readWriteLock.tryLockForWrite())
failureCount++;
testsTurn.release();
threadsTurn.acquire();
if (!readWriteLock.tryLockForWrite())
failureCount++;
if (!lockCount.testAndSetRelaxed(0, 1))
failureCount++;
if (!lockCount.testAndSetRelaxed(1, 0))
failureCount++;
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
if (readWriteLock.tryLockForWrite(1000))
failureCount++;
testsTurn.release();
threadsTurn.acquire();
if (!readWriteLock.tryLockForWrite(1000))
failureCount++;
if (!lockCount.testAndSetRelaxed(0, 1))
failureCount++;
if (!lockCount.testAndSetRelaxed(1, 0))
failureCount++;
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
}
int failureCount;
};
Thread thread;
thread.start();
testsTurn.acquire();
readWriteLock.lockForRead();
lockCount.ref();
threadsTurn.release();
testsTurn.acquire();
lockCount.deref();
readWriteLock.unlock();
threadsTurn.release();
testsTurn.acquire();
readWriteLock.lockForRead();
lockCount.ref();
//.........这里部分代码省略.........