当前位置: 首页>>代码示例>>C++>>正文


C++ QBasicAtomicInt类代码示例

本文整理汇总了C++中QBasicAtomicInt的典型用法代码示例。如果您正苦于以下问题:C++ QBasicAtomicInt类的具体用法?C++ QBasicAtomicInt怎么用?C++ QBasicAtomicInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QBasicAtomicInt类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ThrowingType

 ThrowingType(QBasicAtomicInt &throwControl)
 {
     constructedCount.ref();
     if (throwControl.fetchAndAddRelaxed(-1) != 0)
         throw 0;
 }
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:6,代码来源:tst_qglobalstatic.cpp

示例2: defined

QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
    QHostInfo results;

#if defined(QHOSTINFO_DEBUG)
    qDebug("QHostInfoAgent::fromName(%s) looking up...",
           hostName.toLatin1().constData());
#endif

    // Load res_init on demand.
    static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false);
    if (!triedResolve.loadAcquire()) {
        QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
        if (!triedResolve.load()) {
            resolveLibrary();
            triedResolve.storeRelease(true);
        }
    }

    // If res_init is available, poll it.
    if (local_res_init)
        local_res_init();

    QHostAddress address;
    if (address.setAddress(hostName)) {
        // Reverse lookup
// Reverse lookups using getnameinfo are broken on darwin, use gethostbyaddr instead.
#if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN)
        sockaddr_in sa4;
        sockaddr_in6 sa6;
        sockaddr *sa = 0;
        QT_SOCKLEN_T saSize = 0;
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            sa = (sockaddr *)&sa4;
            saSize = sizeof(sa4);
            memset(&sa4, 0, sizeof(sa4));
            sa4.sin_family = AF_INET;
            sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
        }
        else {
            sa = (sockaddr *)&sa6;
            saSize = sizeof(sa6);
            memset(&sa6, 0, sizeof(sa6));
            sa6.sin6_family = AF_INET6;
            memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr));
        }

        char hbuf[NI_MAXHOST];
        if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
            results.setHostName(QString::fromLatin1(hbuf));
#else
        in_addr_t inetaddr = qt_safe_inet_addr(hostName.toLatin1().constData());
        struct hostent *ent = gethostbyaddr((const char *)&inetaddr, sizeof(inetaddr), AF_INET);
        if (ent)
            results.setHostName(QString::fromLatin1(ent->h_name));
#endif

        if (results.hostName().isEmpty())
            results.setHostName(address.toString());
        results.setAddresses(QList<QHostAddress>() << address);
        return results;
    }

    // IDN support
    QByteArray aceHostname = QUrl::toAce(hostName);
    results.setHostName(hostName);
    if (aceHostname.isEmpty()) {
        results.setError(QHostInfo::HostNotFound);
        results.setErrorString(hostName.isEmpty() ?
                               QCoreApplication::translate("QHostInfoAgent", "No host name given") :
                               QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
        return results;
    }

#if !defined (QT_NO_GETADDRINFO)
    // Call getaddrinfo, and place all IPv4 addresses at the start and
    // the IPv6 addresses at the end of the address list in results.
    addrinfo *res = 0;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_UNSPEC;
#ifdef Q_ADDRCONFIG
    hints.ai_flags = Q_ADDRCONFIG;
#endif

    int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
# ifdef Q_ADDRCONFIG
    if (result == EAI_BADFLAGS) {
        // if the lookup failed with AI_ADDRCONFIG set, try again without it
        hints.ai_flags = 0;
        result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
    }
# endif

    if (result == 0) {
        addrinfo *node = res;
        QList<QHostAddress> addresses;
        while (node) {
#ifdef QHOSTINFO_DEBUG
                qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen;
//.........这里部分代码省略.........
开发者ID:KDE,项目名称:android-qt5-qtbase,代码行数:101,代码来源:qhostinfo_unix.cpp

示例3:

 ~Second()
 {
     order = cleanupOrder.fetchAndAddRelaxed(1);
 }
开发者ID:mpvader,项目名称:qt,代码行数:4,代码来源:tst_qthreadstorage.cpp

示例4:

 ~ThrowingType() { destructedCount.ref(); }
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:1,代码来源:tst_qglobalstatic.cpp

示例5: connManager_prepare

static void connManager_prepare()
{
    int shutdown = appShutdown.fetchAndStoreAcquire(0);
    Q_ASSERT(shutdown == 0 || shutdown == 1);
    Q_UNUSED(shutdown);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:6,代码来源:qnetworkconfigmanager.cpp

示例6: lookupHost

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");

    // generate unique ID
    int id = theIdCounter.fetchAndAddRelaxed(1); 

    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(const 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(const 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(const QHostInfo &)), receiver, member, Qt::QueuedConnection);
        }

        manager->scheduleLookup(runnable);
    }
开发者ID:wpbest,项目名称:copperspice,代码行数:65,代码来源:qhostinfo.cpp

示例7: SPointer

 inline SPointer(const SPointer &other) { count.ref(); }
开发者ID:KDE,项目名称:android-qt,代码行数:1,代码来源:tst_qthreadstorage.cpp

示例8:

 inline ~SPointer() { count.deref(); }
开发者ID:KDE,项目名称:android-qt,代码行数:1,代码来源:tst_qthreadstorage.cpp


注:本文中的QBasicAtomicInt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。