本文整理汇总了C++中Q_BASIC_ATOMIC_INITIALIZER函数的典型用法代码示例。如果您正苦于以下问题:C++ Q_BASIC_ATOMIC_INITIALIZER函数的具体用法?C++ Q_BASIC_ATOMIC_INITIALIZER怎么用?C++ Q_BASIC_ATOMIC_INITIALIZER使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Q_BASIC_ATOMIC_INITIALIZER函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id.load()) \
metatype_id.store(qRegisterMetaType< QPair<qreal,QColor > >("QPair<qreal,QColor >")); \
return metatype_id.load(); \
} \
示例2: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id) \
metatype_id = qRegisterMetaType< QVector<QPair<qreal,QColor> > >("QVector<QPair<qreal,QColor> >"); \
return metatype_id; \
} \
示例3: unixCheckClockType
static int unixCheckClockType()
{
#if (_POSIX_MONOTONIC_CLOCK-0 == 0) && defined(_SC_MONOTONIC_CLOCK)
// we need a value we can store in a clockid_t that isn't a valid clock
// check if the valid ones are both non-negative or both non-positive
# if CLOCK_MONOTONIC >= 0 && CLOCK_REALTIME >= 0
# define IS_VALID_CLOCK(clock) (clock >= 0)
# define INVALID_CLOCK -1
# elif CLOCK_MONOTONIC <= 0 && CLOCK_REALTIME <= 0
# define IS_VALID_CLOCK(clock) (clock <= 0)
# define INVALID_CLOCK 1
# else
# error "Sorry, your system has weird values for CLOCK_MONOTONIC and CLOCK_REALTIME"
# endif
static QBasicAtomicInt clockToUse = Q_BASIC_ATOMIC_INITIALIZER(INVALID_CLOCK);
int clock = clockToUse.loadAcquire();
if (Q_LIKELY(IS_VALID_CLOCK(clock)))
return clock;
// detect if the system supports monotonic timers
clock = sysconf(_SC_MONOTONIC_CLOCK) > 0 ? CLOCK_MONOTONIC : CLOCK_REALTIME;
clockToUse.storeRelease(clock);
return clock;
# undef INVALID_CLOCK
# undef IS_VALID_CLOCK
#elif (_POSIX_MONOTONIC_CLOCK-0) > 0
return CLOCK_MONOTONIC;
#else
return CLOCK_REALTIME;
#endif
}
示例4: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id.load()) \
metatype_id.store(qRegisterMetaType< QHash<int,QByteArray > >("QHash<int,QByteArray >")); \
return metatype_id.load(); \
} \
示例5: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id) \
metatype_id = qRegisterMetaType< QMap<int,QVariant> >("QMap<int,QVariant>"); \
return metatype_id; \
} \
示例6: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id) \
metatype_id = qRegisterMetaType< QList<QPair<QByteArray,QString> > >("QList<QPair<QByteArray,QString> >"); \
return metatype_id; \
} \
示例7: qt_metatype_id
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id) \
metatype_id = qRegisterMetaType< QMultiMap<QString,QString> >("QMultiMap<QString,QString>"); \
return metatype_id; \
} \
示例8: qt_ignore_sigpipe
// Lifted from Qt. I don't think they would mind. ;)
// Re-lift again from Qt whenever a proper replacement for pthread_once appears
static void qt_ignore_sigpipe()
{
static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0);
if (atom.testAndSetRelaxed(0, 1)) {
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &noaction, 0);
}
}
示例9: messageHandler
static void messageHandler(QtMsgType type, const QMessageLogContext & context, const QString &message)
{
static QBasicAtomicInt counter = Q_BASIC_ATOMIC_INITIALIZER(QTest::maxWarnings);
if (QTest::TestLoggers::loggerCount() == 0) {
// if this goes wrong, something is seriously broken.
qInstallMessageHandler(oldMessageHandler);
QTEST_ASSERT(QTest::TestLoggers::loggerCount() != 0);
}
if (handleIgnoredMessage(type, message))
// the message is expected, so just swallow it.
return;
QString msg = qFormatLogMessage(type, context, message);
if (type != QtFatalMsg) {
if (counter.load() <= 0)
return;
if (!counter.deref()) {
QTest::TestLoggers::addMessage(QAbstractTestLogger::QSystem,
QStringLiteral("Maximum amount of warnings exceeded. Use -maxwarnings to override."));
return;
}
}
switch (type) {
case QtDebugMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QDebug, msg);
break;
case QtCriticalMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QSystem, msg);
break;
case QtWarningMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QWarning, msg);
break;
case QtFatalMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QFatal, msg);
/* Right now, we're inside the custom message handler and we're
* being qt_message_output in qglobal.cpp. After we return from
* this function, it will proceed with calling exit() and abort()
* and hence crash. Therefore, we call these logging functions such
* that we wrap up nicely, and in particular produce well-formed XML. */
QTestResult::addFailure("Received a fatal error.", "Unknown file", 0);
QTestLog::leaveTestFunction();
QTestLog::stopLogging();
break;
}
}
示例10: openFlags
KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags,
QStandardPaths::StandardLocation resourceType)
: openFlags(flags), resourceType(resourceType), mBackend(Q_NULLPTR),
bDynamicBackend(true), bDirty(false), bReadDefaults(false),
bFileImmutable(false), bForceGlobal(false), bSuppressGlobal(false),
configState(KConfigBase::NoAccess)
{
static QBasicAtomicInt use_etc_kderc = Q_BASIC_ATOMIC_INITIALIZER(-1);
if (use_etc_kderc.load() < 0) {
use_etc_kderc.store( !qEnvironmentVariableIsSet("KDE_SKIP_KDERC")); // for unit tests
}
if (use_etc_kderc.load()) {
etc_kderc =
#ifdef Q_OS_WIN
QFile::decodeName(qgetenv("WINDIR") + "/kde5rc");
#else
QStringLiteral("/etc/kde5rc");
#endif
if (!QFileInfo(etc_kderc).isReadable()) {
etc_kderc.clear();
}
}
// if (!mappingsRegistered) {
// KEntryMap tmp;
// if (!etc_kderc.isEmpty()) {
// QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(etc_kderc, QLatin1String("INI"));
// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseDefaults);
// }
// const QString kde5rc(QDir::home().filePath(".kde5rc"));
// if (KStandardDirs::checkAccess(kde5rc, R_OK)) {
// QExplicitlySharedDataPointer<KConfigBackend> backend = KConfigBackend::create(kde5rc, QLatin1String("INI"));
// backend->parseConfig( "en_US", tmp, KConfigBackend::ParseOptions());
// }
// KConfigBackend::registerMappings(tmp);
// mappingsRegistered = true;
// }
setLocale(QLocale().name());
}
示例11: getticks
static qint64 getticks()
{
#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
clockid_t clockId;
#ifndef _POSIX_THREAD_CPUTIME
clockId = CLOCK_REALTIME;
#elif (_POSIX_THREAD_CPUTIME-0 <= 0)
// if we don't have CLOCK_THREAD_CPUTIME_ID, we have to just use elapsed realtime instead
clockId = CLOCK_REALTIME;
# if (_POSIX_THREAD_CPUTIME-0 == 0)
// detect availablility of CLOCK_THREAD_CPUTIME_ID
static QBasicAtomicInt sUseThreadCpuTime = Q_BASIC_ATOMIC_INITIALIZER(-2);
int useThreadCpuTime = sUseThreadCpuTime.load();
if (useThreadCpuTime == -2) {
// sysconf() will return either -1L or _POSIX_VERSION
// (don't care about sysconf's exact return value)
useThreadCpuTime = sysconf(_SC_THREAD_CPUTIME) == -1L ? -1 : 0 ;
sUseThreadCpuTime.store(useThreadCpuTime); // might happen multiple times, but doesn't matter
}
if (useThreadCpuTime != -1)
clockId = CLOCK_THREAD_CPUTIME_ID;
# endif
#else
clockId = CLOCK_THREAD_CPUTIME_ID;
#endif
struct timespec ts;
if (clock_gettime(clockId, &ts) == -1)
return 0;
return (ts.tv_sec * 1000000000) + ts.tv_nsec;
#else
// no clock_gettime(), fall back to wall time
struct timeval tv;
gettimeofday(&tv, 0);
return (tv.tv_sec * 1000000) + tv.tv_usec;
#endif
}
示例12: Q_Q
void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
{
Q_Q(QVariantAnimation);
const qreal startProgress = currentInterval.start.first;
const qreal endProgress = currentInterval.end.first;
const qreal localProgress = (progress - startProgress) / (endProgress - startProgress);
QVariant ret = q->interpolated(currentInterval.start.second,
currentInterval.end.second,
localProgress);
qSwap(currentValue, ret);
q->updateCurrentValue(currentValue);
static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0);
if (!changedSignalIndex) {
//we keep the mask so that we emit valueChanged only when needed (for performance reasons)
changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
}
if (isSignalConnected(changedSignalIndex) && currentValue != ret) {
//the value has changed
emit q->valueChanged(currentValue);
}
}
示例13: resolveLibrary
QT_BEGIN_NAMESPACE
static void resolveLibrary()
{
static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false);
if (!triedResolve.loadAcquire()) {
#ifndef QT_NO_THREAD
QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle));
#endif
if (!triedResolve.load()) {
local_WlanOpenHandle = (WlanOpenHandleProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle");
local_WlanRegisterNotification = (WlanRegisterNotificationProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification");
local_WlanEnumInterfaces = (WlanEnumInterfacesProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces");
local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList");
local_WlanQueryInterface = (WlanQueryInterfaceProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface");
local_WlanConnect = (WlanConnectProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect");
local_WlanDisconnect = (WlanDisconnectProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect");
local_WlanScan = (WlanScanProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan");
local_WlanFreeMemory = (WlanFreeMemoryProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory");
local_WlanCloseHandle = (WlanCloseHandleProto)
QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle");
triedResolve.storeRelease(true);
}
}
}
示例14: QNetworkAccessBackendFactoryData
QNetworkAccessBackendFactoryData() : mutex(QMutex::Recursive)
{
valid.ref();
}
~QNetworkAccessBackendFactoryData()
{
QMutexLocker locker(&mutex); // why do we need to lock?
valid.deref();
}
QMutex mutex;
//this is used to avoid (re)constructing factory data from destructors of other global classes
static QBasicAtomicInt valid;
};
Q_GLOBAL_STATIC(QNetworkAccessBackendFactoryData, factoryData)
QBasicAtomicInt QNetworkAccessBackendFactoryData::valid = Q_BASIC_ATOMIC_INITIALIZER(0);
QNetworkAccessBackendFactory::QNetworkAccessBackendFactory()
{
QMutexLocker locker(&factoryData()->mutex);
factoryData()->append(this);
}
QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory()
{
if (QNetworkAccessBackendFactoryData::valid.load()) {
QMutexLocker locker(&factoryData()->mutex);
factoryData()->removeAll(this);
}
}
示例15: Q_BASIC_ATOMIC_INITIALIZER
* return -1 / EWOULDBLOCK, in which case we have to start over. And even if we
* are woken up directly by a FUTEX_WAKE, we need to acquire the mutex, so we
* start over again.
*
* UNLOCKING (non-recursive):
*
* To unlock, we need to set a value of 0x0 to indicate it's unlocked. The
* first attempt is a testAndSetRelease operation from 0x1 to 0x0. If that
* succeeds, we're done.
*
* If it fails, unlockInternal() is called. The only possibility is that the
* mutex value was 0x3, which indicates some other thread is waiting or was
* waiting in the past. We then set the mutex to 0x0 and perform a FUTEX_WAKE.
*/
static QBasicAtomicInt futexFlagSupport = Q_BASIC_ATOMIC_INITIALIZER(-1);
static int checkFutexPrivateSupport()
{
int value = 0;
#if defined(FUTEX_PRIVATE_FLAG)
// check if the kernel supports extra futex flags
// FUTEX_PRIVATE_FLAG appeared in v2.6.22
Q_STATIC_ASSERT(FUTEX_PRIVATE_FLAG != 0x80000000);
// try an operation that has no side-effects: wake up 42 threads
// futex will return -1 (errno==ENOSYS) if the flag isn't supported
// there should be no other error conditions
value = syscall(__NR_futex, &futexFlagSupport,
FUTEX_WAKE | FUTEX_PRIVATE_FLAG,
42, 0, 0, 0);