本文整理汇总了C++中QAtomicInt::ref方法的典型用法代码示例。如果您正苦于以下问题:C++ QAtomicInt::ref方法的具体用法?C++ QAtomicInt::ref怎么用?C++ QAtomicInt::ref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAtomicInt
的用法示例。
在下文中一共展示了QAtomicInt::ref方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: recursiveResult
int recursiveResult(int level)
{
count.ref();
if (--level > 0) {
QFuture<int> f1 = run(recursiveResult, level);
QFuture<int> f2 = run(recursiveResult, level);
return f1.result() + f2.result();
}
return 1;
}
示例3: recursiveRun
void recursiveRun(int level)
{
count.ref();
if (--level > 0) {
QFuture<void> f1 = run(recursiveRun, level);
QFuture<void> f2 = run(recursiveRun, level);
f1.waitForFinished();
f2.waitForFinished();
}
}
示例4: 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();
}
示例5: XOpenDisplay
void QEglFSX11Hooks::platformInit()
{
m_display = XOpenDisplay(0);
if (!m_display)
qFatal("Could not open display");
XSetEventQueueOwner(m_display, XCBOwnsEventQueue);
m_connection = XGetXCBConnection(m_display);
running.ref();
xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(m_connection));
m_connectionEventListener = xcb_generate_id(m_connection);
xcb_create_window(m_connection, XCB_COPY_FROM_PARENT,
m_connectionEventListener, it.data->root,
0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
it.data->root_visual, 0, 0);
m_eventReader = new EventReader(this);
m_eventReader->start();
}
示例6: addRef
void addRef() { ref.ref(); }
示例7: run
void run()
{
quint64 i = 0;
while (t.elapsed() < one_minute) {
i++;
uint nb = (i * 9 + lockCount.load() * 13) % threadCount;
QMutexLocker locker(&mutex[nb]);
if (sentinel[nb].load()) errorCount.ref();
if (sentinel[nb].fetchAndAddRelaxed(5)) errorCount.ref();
if (!sentinel[nb].testAndSetRelaxed(5, 0)) errorCount.ref();
if (sentinel[nb].load()) errorCount.ref();
lockCount.ref();
nb = (nb * 17 + i * 5 + lockCount.load() * 3) % threadCount;
if (mutex[nb].tryLock()) {
if (sentinel[nb].load()) errorCount.ref();
if (sentinel[nb].fetchAndAddRelaxed(16)) errorCount.ref();
if (!sentinel[nb].testAndSetRelaxed(16, 0)) errorCount.ref();
if (sentinel[nb].load()) errorCount.ref();
lockCount.ref();
mutex[nb].unlock();
}
nb = (nb * 15 + i * 47 + lockCount.load() * 31) % threadCount;
if (mutex[nb].tryLock(2)) {
if (sentinel[nb].load()) errorCount.ref();
if (sentinel[nb].fetchAndAddRelaxed(53)) errorCount.ref();
if (!sentinel[nb].testAndSetRelaxed(53, 0)) errorCount.ref();
if (sentinel[nb].load()) errorCount.ref();
lockCount.ref();
mutex[nb].unlock();
}
}
}
示例8: 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();
//.........这里部分代码省略.........
示例9: forwardMessage
void LogForwardThread::forwardMessage(LogMessage *msg)
{
#ifdef DUMP_PACKET
QList<QByteArray>::const_iterator it = msg->begin();
int i = 0;
for (; it != msg->end(); ++it, i++)
{
QByteArray buf = *it;
cout << i << ":\t" << buf.size() << endl << "\t"
<< buf.toHex().constData() << endl << "\t"
<< buf.constData() << endl;
}
#endif
msgsSinceHeartbeat.ref();
// First section is the client id
QByteArray clientBa = msg->first();
QString clientId = QString(clientBa.toHex());
QByteArray json = msg->at(1);
if (json.size() == 0)
{
// This is either a ping response or a first gasp
logClientMapMutex.lock();
LoggerListItem *logItem = logClientMap.value(clientId, NULL);
logClientMapMutex.unlock();
if (!logItem)
{
// Send an initial ping so the client knows we are in the house
emit pingClient(clientId);
}
else
{
// cout << "pong " << clientId.toLocal8Bit().constData() << endl;
loggingGetTimeStamp(&logItem->epoch, NULL);
}
return;
}
QMutexLocker lock(&logClientMapMutex);
LoggerListItem *logItem = logClientMap.value(clientId, NULL);
// cout << "msg " << clientId.toLocal8Bit().constData() << endl;
if (logItem)
{
loggingGetTimeStamp(&logItem->epoch, NULL);
}
else
{
LoggingItem *item = LoggingItem::create(json);
logClientCount.ref();
LOG(VB_FILE, LOG_DEBUG, QString("New Logging Client: ID: %1 (#%2)")
.arg(clientId).arg(logClientCount.fetchAndAddOrdered(0)));
#ifndef NOLOGSERVER
// TODO FIXME This is not thread-safe!
if (logClientCount.fetchAndAddOrdered(0) > 1 && m_shutdownTimer &&
m_shutdownTimer->isActive())
{
LOG(VB_GENERAL, LOG_INFO, "Aborting shutdown timer");
m_shutdownTimer->stop();
}
#endif
QMutexLocker lock2(&loggerMapMutex);
QMutexLocker lock3(&logRevClientMapMutex);
// Need to find or create the loggers
LoggerList *loggers = new LoggerList;
LoggerBase *logger;
// FileLogger from logFile
QString logfile = item->logFile();
logfile.detach();
if (!logfile.isEmpty())
{
logger = FileLogger::create(logfile, lock2.mutex());
ClientList *clients = logRevClientMap.value(logger);
if (clients)
clients->insert(0, clientId);
if (logger && loggers)
loggers->insert(0, logger);
}
#ifndef _WIN32
// SyslogLogger from facility
int facility = item->facility();
#if CONFIG_SYSTEMD_JOURNAL
if ((facility > 0) || (facility == SYSTEMD_JOURNAL_FACILITY))
{
logger = SyslogLogger::create(lock2.mutex(), facility > 0);
#else
if (facility > 0)
{
//.........这里部分代码省略.........