本文整理汇总了C++中QAtomicInt::fetchAndAddRelaxed方法的典型用法代码示例。如果您正苦于以下问题:C++ QAtomicInt::fetchAndAddRelaxed方法的具体用法?C++ QAtomicInt::fetchAndAddRelaxed怎么用?C++ QAtomicInt::fetchAndAddRelaxed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAtomicInt
的用法示例。
在下文中一共展示了QAtomicInt::fetchAndAddRelaxed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: locker
/**
* Network streaming request
*/
NetStream::NetStream(const QUrl &url, EMode mode /*= kPreferCache*/) :
m_id(s_nRequest.fetchAndAddRelaxed(1)),
m_state(kClosed),
m_pending(0),
m_reply(0),
m_nRedirections(0),
m_size(-1),
m_pos(0)
{
setObjectName("NetStream " + url.toString());
m_request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
mode == kAlwaysCache ? QNetworkRequest::AlwaysCache :
mode == kPreferCache ? QNetworkRequest::PreferCache :
mode == kNeverCache ? QNetworkRequest::AlwaysNetwork :
QNetworkRequest::PreferNetwork );
// Receive requestStarted signals from NAMThread when it processes a NetStreamRequest
connect(&NAMThread::manager(), SIGNAL(requestStarted(int, QNetworkReply*)),
this, SLOT(slotRequestStarted(int, QNetworkReply*)), Qt::DirectConnection );
QMutexLocker locker(&m_mutex);
if (Request(url))
m_state = kPending;
}
示例2: lookupHost
/*!
Looks up the IP address(es) associated with host name \a name, and
returns an ID for the lookup. When the result of the lookup is
ready, the slot or signal \a member in \a receiver is called with
a QHostInfo argument. The QHostInfo object can then be inspected
to get the results of the lookup.
The lookup is performed by a single function call, for example:
\snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 2
The implementation of the slot prints basic information about the
addresses returned by the lookup, or reports an error if it failed:
\snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 3
If you pass a literal IP address to \a name instead of a host name,
QHostInfo will search for the domain name for the IP (i.e., QHostInfo will
perform a \e reverse lookup). On success, the resulting QHostInfo will
contain both the resolved domain name and IP addresses for the host
name. Example:
\snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 4
\note There is no guarantee on the order the signals will be emitted
if you start multiple requests with lookupHost().
\sa abortHostLookup(), addresses(), error(), fromName()
*/
int QHostInfo::lookupHost(const QString &name, QObject *receiver,
const char *member)
{
#if defined QHOSTINFO_DEBUG
qDebug("QHostInfo::lookupHost(\"%s\", %p, %s)",
name.toLatin1().constData(), receiver, member ? member + 1 : 0);
#endif
if (!QAbstractEventDispatcher::instance(QThread::currentThread())) {
qWarning("QHostInfo::lookupHost() called with no event dispatcher");
return -1;
}
qRegisterMetaType<QHostInfo>("QHostInfo");
int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID
if (name.isEmpty()) {
if (!receiver)
return -1;
QHostInfo hostInfo(id);
hostInfo.setError(QHostInfo::HostNotFound);
hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
QScopedPointer<QHostInfoResult> result(new QHostInfoResult);
QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
receiver, member, Qt::QueuedConnection);
result.data()->emitResultsReady(hostInfo);
return id;
}
QHostInfoLookupManager *manager = theHostInfoLookupManager();
if (manager) {
// the application is still alive
if (manager->cache.isEnabled()) {
// check cache first
bool valid = false;
QHostInfo info = manager->cache.get(name, &valid);
if (valid) {
if (!receiver)
return -1;
info.setLookupId(id);
QHostInfoResult result;
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
result.emitResultsReady(info);
return id;
}
}
// cache is not enabled or it was not in the cache, do normal lookup
QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id);
if (receiver)
QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection);
manager->scheduleLookup(runnable);
}
return id;
}
示例3: 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;
}
示例4: runIterations
bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *)
{
iterations.fetchAndAddRelaxed(end - begin);
#ifdef PRINT
qDebug() << QThread::currentThread() << "iteration" << begin << "to" << end << "(exclusive)";
#endif
return false;
}
示例5: winIdGenerator
QT_BEGIN_NAMESPACE
QFbWindow::QFbWindow(QWindow *window)
: QPlatformWindow(window), mBackingStore(0)
{
static QAtomicInt winIdGenerator(1);
mWindowId = winIdGenerator.fetchAndAddRelaxed(1);
platformScreen()->addWindow(this);
}
示例6: trackerBus
QDBusConnection trackerBus(bool is_thread_private)
{
if(!is_thread_private)
return QDBusConnection::sessionBus();
// Create a separate D-Bus connection for each thread. Use ClosingDBusConnection so
// that the bus gets disconnected when the thread storage is deleted.
if (!dbus_tls.hasLocalData()) {
QString id = QString::number(counter.fetchAndAddRelaxed(1))
.prepend("libqttracker-dbus-");
dbus_tls.setLocalData(new ClosingDBusConnection
(QDBusConnection::connectToBus(QDBusConnection::SessionBus, id)));
}
return *dbus_tls.localData();
}
示例7: createMetaObject
bool PropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Object *obj, QQmlPropertyCache *baseTypeCache)
{
QQmlPropertyCache *cache = baseTypeCache->copyAndReserve(QQmlEnginePrivate::get(enginePrivate),
obj->propertyCount(),
obj->functionCount() + obj->propertyCount() + obj->signalCount(),
obj->signalCount() + obj->propertyCount());
propertyCaches[objectIndex] = cache;
struct TypeData {
QV4::CompiledData::Property::Type dtype;
int metaType;
} builtinTypes[] = {
{ QV4::CompiledData::Property::Var, qMetaTypeId<QJSValue>() },
{ QV4::CompiledData::Property::Variant, QMetaType::QVariant },
{ QV4::CompiledData::Property::Int, QMetaType::Int },
{ QV4::CompiledData::Property::Bool, QMetaType::Bool },
{ QV4::CompiledData::Property::Real, QMetaType::Double },
{ QV4::CompiledData::Property::String, QMetaType::QString },
{ QV4::CompiledData::Property::Url, QMetaType::QUrl },
{ QV4::CompiledData::Property::Color, QMetaType::QColor },
{ QV4::CompiledData::Property::Font, QMetaType::QFont },
{ QV4::CompiledData::Property::Time, QMetaType::QTime },
{ QV4::CompiledData::Property::Date, QMetaType::QDate },
{ QV4::CompiledData::Property::DateTime, QMetaType::QDateTime },
{ QV4::CompiledData::Property::Rect, QMetaType::QRectF },
{ QV4::CompiledData::Property::Point, QMetaType::QPointF },
{ QV4::CompiledData::Property::Size, QMetaType::QSizeF },
{ QV4::CompiledData::Property::Vector2D, QMetaType::QVector2D },
{ QV4::CompiledData::Property::Vector3D, QMetaType::QVector3D },
{ QV4::CompiledData::Property::Vector4D, QMetaType::QVector4D },
{ QV4::CompiledData::Property::Matrix4x4, QMetaType::QMatrix4x4 },
{ QV4::CompiledData::Property::Quaternion, QMetaType::QQuaternion }
};
static const uint builtinTypeCount = sizeof(builtinTypes) / sizeof(TypeData);
QByteArray newClassName;
if (objectIndex == compiler->rootObjectIndex()) {
QString path = compiler->data()->url.path();
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
if (lastSlash > -1) {
QString nameBase = path.mid(lastSlash + 1, path.length()-lastSlash-5);
if (!nameBase.isEmpty() && nameBase.at(0).isUpper())
newClassName = nameBase.toUtf8() + "_QMLTYPE_" +
QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
}
}
if (newClassName.isEmpty()) {
newClassName = QQmlMetaObject(baseTypeCache).className();
newClassName.append("_QML_");
newClassName.append(QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1)));
}
cache->_dynamicClassName = newClassName;
int aliasCount = 0;
int varPropCount = 0;
QmlIR::PropertyResolver resolver(baseTypeCache);
for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next) {
if (p->type == QV4::CompiledData::Property::Alias)
aliasCount++;
else if (p->type == QV4::CompiledData::Property::Var)
varPropCount++;
// No point doing this for both the alias and non alias cases
bool notInRevision = false;
QQmlPropertyData *d = resolver.property(stringAt(p->nameIndex), ¬InRevision);
if (d && d->isFinal()) {
compiler->recordError(p->location, tr("Cannot override FINAL property"));
return false;
}
}
typedef QQmlVMEMetaData VMD;
QByteArray &dynamicData = vmeMetaObjects[objectIndex] = QByteArray(sizeof(QQmlVMEMetaData)
+ obj->propertyCount() * sizeof(VMD::PropertyData)
+ obj->functionCount() * sizeof(VMD::MethodData)
+ aliasCount * sizeof(VMD::AliasData), 0);
int effectivePropertyIndex = cache->propertyIndexCacheStart;
int effectiveMethodIndex = cache->methodIndexCacheStart;
// For property change signal override detection.
// We prepopulate a set of signal names which already exist in the object,
// and throw an error if there is a signal/method defined as an override.
QSet<QString> seenSignals;
seenSignals << QStringLiteral("destroyed") << QStringLiteral("parentChanged") << QStringLiteral("objectNameChanged");
QQmlPropertyCache *parentCache = cache;
while ((parentCache = parentCache->parent())) {
if (int pSigCount = parentCache->signalCount()) {
int pSigOffset = parentCache->signalOffset();
for (int i = pSigOffset; i < pSigCount; ++i) {
QQmlPropertyData *currPSig = parentCache->signal(i);
// XXX TODO: find a better way to get signal name from the property data :-/
for (QQmlPropertyCache::StringCache::ConstIterator iter = parentCache->stringCache.begin();
iter != parentCache->stringCache.end(); ++iter) {
if (currPSig == (*iter).second) {
//.........这里部分代码省略.........