本文整理汇总了C++中QAtomicInt::load方法的典型用法代码示例。如果您正苦于以下问题:C++ QAtomicInt::load方法的具体用法?C++ QAtomicInt::load怎么用?C++ QAtomicInt::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAtomicInt
的用法示例。
在下文中一共展示了QAtomicInt::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
}
}
示例2: 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())));
}
}
示例3: 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);
}
示例4: 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());
}
}
示例5: workerCount
int TActionWorker::workerCount()
{
#if QT_VERSION >= 0x050000
return workerCounter.load();
#else
return (int)workerCounter;
#endif
}
示例6: threadCount
int TActionThread::threadCount()
{
#if QT_VERSION >= 0x050000
return threadCounter.load();
#else
return (int)threadCounter;
#endif
}
示例7: run
void run()
{
testRwlock.lockForWrite();
while(release.load()==false) {
RWTESTSLEEP
}
testRwlock.unlock();
}
示例8: recursive
void tst_QtConcurrentRun::recursive()
{
int levels = 15;
for (int i = 0; i < QThread::idealThreadCount(); ++i) {
count.store(0);
QThreadPool::globalInstance()->setMaxThreadCount(i);
recursiveRun(levels);
QCOMPARE(count.load(), (int)pow(2.0, levels) - 1);
}
for (int i = 0; i < QThread::idealThreadCount(); ++i) {
count.store(0);
QThreadPool::globalInstance()->setMaxThreadCount(i);
recursiveResult(levels);
QCOMPARE(count.load(), (int)pow(2.0, levels) - 1);
}
}
示例9: 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);
}
}
示例10: 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);
}
示例11: run
void EventReader::run()
{
Qt::MouseButtons buttons;
xcb_generic_event_t *event;
while (running.load() && (event = xcb_wait_for_event(m_hooks->connection()))) {
uint response_type = event->response_type & ~0x80;
switch (response_type) {
case XCB_BUTTON_PRESS: {
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
QPoint p(press->event_x, press->event_y);
buttons = (buttons & ~0x7) | translateMouseButtons(press->state);
buttons |= translateMouseButton(press->detail);
QWindowSystemInterface::handleMouseEvent(0, press->time, p, p, buttons);
break;
}
case XCB_BUTTON_RELEASE: {
xcb_button_release_event_t *release = (xcb_button_release_event_t *)event;
QPoint p(release->event_x, release->event_y);
buttons = (buttons & ~0x7) | translateMouseButtons(release->state);
buttons &= ~translateMouseButton(release->detail);
QWindowSystemInterface::handleMouseEvent(0, release->time, p, p, buttons);
break;
}
case XCB_MOTION_NOTIFY: {
xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event;
QPoint p(motion->event_x, motion->event_y);
QWindowSystemInterface::handleMouseEvent(0, motion->time, p, p, buttons);
break;
}
case XCB_CLIENT_MESSAGE: {
xcb_client_message_event_t *client = (xcb_client_message_event_t *) event;
const xcb_atom_t *atoms = m_hooks->atoms();
if (client->format == 32
&& client->type == atoms[Atoms::WM_PROTOCOLS]
&& client->data.data32[0] == atoms[Atoms::WM_DELETE_WINDOW]) {
QWindow *window = m_hooks->platformWindow() ? m_hooks->platformWindow()->window() : 0;
if (window)
QWindowSystemInterface::handleCloseEvent(window);
}
break;
}
default:
break;
}
}
}
示例12: QAudioBufferPrivate
QAudioBufferPrivate *QAudioBufferPrivate::clone()
{
// We want to create a single bufferprivate with a
// single qaab
// This should only be called when the count is > 1
Q_ASSERT(mCount.load() > 1);
if (mProvider) {
QAbstractAudioBuffer *abuf = mProvider->clone();
if (!abuf) {
abuf = new QMemoryAudioBufferProvider(mProvider->constData(), mProvider->frameCount(), mProvider->format(), mProvider->startTime());
}
if (abuf) {
return new QAudioBufferPrivate(abuf);
}
}
return 0;
}
示例13: allocatedObjects
int QcepObject::allocatedObjects()
{
return s_ObjectAllocateCount.load();
}
示例14: shouldThrottleThread
bool shouldThrottleThread()
{
const int load = iterations.load();
return (load > 100 && load < 200);
}
示例15: instantiate
void tst_QtConcurrentIterateKernel::instantiate()
{
startThreadEngine(new PrintFor(0, 40)).startBlocking();
QCOMPARE(iterations.load(), 40);
}