Use QT_CONFIG feature checks for sharedmemory and systemsemaphores
Change-Id: I86d0e4c5f279486f5fd6ef086dd913e813d0186d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>bb10
parent
dbb3fdafac
commit
4a4a0b6d1f
|
|
@ -26,7 +26,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
|
||||
#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
/*!
|
||||
\internal
|
||||
|
||||
|
|
@ -76,9 +76,9 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,
|
|||
return QDir::tempPath() + u'/' + result;
|
||||
#endif
|
||||
}
|
||||
#endif // QT_NO_SHAREDMEMORY && QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
|
||||
/*!
|
||||
\class QSharedMemory
|
||||
|
|
@ -283,7 +283,7 @@ bool QSharedMemoryPrivate::initKey()
|
|||
{
|
||||
if (!cleanHandle())
|
||||
return false;
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
systemSemaphore.setKey(QString(), 1);
|
||||
systemSemaphore.setKey(key, 1);
|
||||
if (systemSemaphore.error() != QSystemSemaphore::NoError) {
|
||||
|
|
@ -370,7 +370,7 @@ bool QSharedMemory::create(qsizetype size, AccessMode mode)
|
|||
if (!d->initKey())
|
||||
return false;
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
#ifndef Q_OS_WIN
|
||||
// Take ownership and force set initialValue because the semaphore
|
||||
// might have already existed from a previous crash.
|
||||
|
|
@ -379,7 +379,7 @@ bool QSharedMemory::create(qsizetype size, AccessMode mode)
|
|||
#endif
|
||||
|
||||
QString function = "QSharedMemory::create"_L1;
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
QSharedMemoryLocker lock(this);
|
||||
if (!d->key.isNull() && !d->tryLocker(&lock, function))
|
||||
return false;
|
||||
|
|
@ -443,7 +443,7 @@ bool QSharedMemory::attach(AccessMode mode)
|
|||
|
||||
if (isAttached() || !d->initKey())
|
||||
return false;
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
QSharedMemoryLocker lock(this);
|
||||
if (!d->key.isNull() && !d->tryLocker(&lock, "QSharedMemory::attach"_L1))
|
||||
return false;
|
||||
|
|
@ -483,7 +483,7 @@ bool QSharedMemory::detach()
|
|||
if (!isAttached())
|
||||
return false;
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
QSharedMemoryLocker lock(this);
|
||||
if (!d->key.isNull() && !d->tryLocker(&lock, "QSharedMemory::detach"_L1))
|
||||
return false;
|
||||
|
|
@ -531,7 +531,7 @@ const void *QSharedMemory::data() const
|
|||
return d->memory;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
/*!
|
||||
This is a semaphore that locks the shared memory segment for access
|
||||
by this process and returns \c true. If another process has locked the
|
||||
|
|
@ -581,7 +581,7 @@ bool QSharedMemory::unlock()
|
|||
d->error = QSharedMemory::LockError;
|
||||
return false;
|
||||
}
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
/*!
|
||||
\enum QSharedMemory::SharedMemoryError
|
||||
|
|
@ -638,7 +638,7 @@ QString QSharedMemory::errorString() const
|
|||
return d->errorString;
|
||||
}
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
|
||||
class QSharedMemoryPrivate;
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public:
|
|||
const void* constData() const;
|
||||
const void *data() const;
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
bool lock();
|
||||
bool unlock();
|
||||
#endif
|
||||
|
|
@ -93,7 +93,7 @@ private:
|
|||
#endif
|
||||
};
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
#include "qsharedmemory_p.h"
|
||||
#include <qdebug.h>
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QSharedMemoryPrivate::QSharedMemoryPrivate()
|
||||
: QObjectPrivate(), memory(0), size(0), error(QSharedMemory::NoError),
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
systemSemaphore(QString()), lockedByMe(false),
|
||||
#endif
|
||||
unix_key(0)
|
||||
|
|
@ -29,18 +29,18 @@ key_t QSharedMemoryPrivate::handle()
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
|
||||
#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
|
||||
{
|
||||
Q_UNUSED(fileName);
|
||||
Q_UNIMPLEMENTED();
|
||||
return 0;
|
||||
}
|
||||
#endif // QT_NO_SHAREDMEMORY && QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
|
||||
bool QSharedMemoryPrivate::cleanHandle()
|
||||
{
|
||||
|
|
@ -71,4 +71,4 @@ bool QSharedMemoryPrivate::detach()
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
#ifdef QT_NO_SHAREDMEMORY
|
||||
# ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if !QT_CONFIG(sharedmemory)
|
||||
# if QT_CONFIG(systemsemaphore)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ QT_END_NAMESPACE
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
/*!
|
||||
Helper class
|
||||
*/
|
||||
|
|
@ -78,7 +78,7 @@ public:
|
|||
private:
|
||||
QSharedMemory *q_sm;
|
||||
};
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
class Q_AUTOTEST_EXPORT QSharedMemoryPrivate
|
||||
#ifndef QT_NO_QOBJECT
|
||||
|
|
@ -98,7 +98,7 @@ public:
|
|||
QString nativeKey;
|
||||
QSharedMemory::SharedMemoryError error;
|
||||
QString errorString;
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
QSystemSemaphore systemSemaphore;
|
||||
bool lockedByMe;
|
||||
#endif
|
||||
|
|
@ -121,7 +121,7 @@ public:
|
|||
|
||||
void setErrorString(QLatin1StringView function);
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
bool tryLocker(QSharedMemoryLocker *locker, const QString &function) {
|
||||
if (!locker->lock()) {
|
||||
errorString = QSharedMemory::tr("%1: unable to lock").arg(function);
|
||||
|
|
@ -130,7 +130,7 @@ public:
|
|||
}
|
||||
return true;
|
||||
}
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
private:
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
@ -144,7 +144,7 @@ private:
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#endif // QSHAREDMEMORY_P_H
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#ifdef QT_POSIX_IPC
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -195,6 +195,6 @@ bool QSharedMemoryPrivate::detach()
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#endif // QT_POSIX_IPC
|
||||
|
|
|
|||
|
|
@ -13,18 +13,18 @@
|
|||
|
||||
#ifndef QT_POSIX_IPC
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif //QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#include "private/qcore_unix_p.h"
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
|
@ -63,9 +63,9 @@ key_t QSharedMemoryPrivate::handle()
|
|||
return unix_key;
|
||||
}
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
|
||||
#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
/*!
|
||||
\internal
|
||||
Creates the unix file if needed.
|
||||
|
|
@ -88,9 +88,9 @@ int QT_PREPEND_NAMESPACE(QSharedMemoryPrivate)::createUnixKeyFile(const QString
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
#endif // QT_NO_SHAREDMEMORY && QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
|
||||
bool QSharedMemoryPrivate::cleanHandle()
|
||||
{
|
||||
|
|
@ -221,6 +221,6 @@ bool QSharedMemoryPrivate::detach()
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#endif // QT_POSIX_IPC
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
#include <sys/types.h>
|
||||
#ifndef QT_POSIX_IPC
|
||||
#include <sys/ipc.h>
|
||||
|
|
@ -21,11 +21,11 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif //QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
#include "private/qcore_unix_p.h"
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QSharedMemoryPrivate::QSharedMemoryPrivate() :
|
||||
|
|
@ -33,7 +33,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate() :
|
|||
QObjectPrivate(),
|
||||
#endif
|
||||
memory(nullptr), size(0), error(QSharedMemory::NoError),
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
systemSemaphore(QString()), lockedByMe(false),
|
||||
#endif
|
||||
#ifndef QT_POSIX_IPC
|
||||
|
|
@ -77,4 +77,4 @@ void QSharedMemoryPrivate::setErrorString(QLatin1StringView function)
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SHAREDMEMORY
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
#ifndef QT_NO_SHAREDMEMORY
|
||||
#if QT_CONFIG(sharedmemory)
|
||||
|
||||
QSharedMemoryPrivate::QSharedMemoryPrivate() :
|
||||
#ifndef QT_NO_QOBJECT
|
||||
|
|
@ -151,7 +151,6 @@ bool QSharedMemoryPrivate::detach()
|
|||
return cleanHandle();
|
||||
}
|
||||
|
||||
#endif //QT_NO_SHAREDMEMORY
|
||||
|
||||
#endif // QT_CONFIG(sharedmemory)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
/*!
|
||||
\class QSystemSemaphore
|
||||
|
|
@ -323,6 +323,6 @@ QString QSystemSemaphore::errorString() const
|
|||
return d->errorString;
|
||||
}
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
class QSystemSemaphorePrivate;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ private:
|
|||
QScopedPointer<QSystemSemaphorePrivate> d;
|
||||
};
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <qdebug.h>
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -44,4 +44,4 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "qsystemsemaphore.h"
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
#include "qcoreapplication.h"
|
||||
#include "qsharedmemory_p.h"
|
||||
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
#endif // QSYSTEMSEMAPHORE_P_H
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#ifdef QT_POSIX_IPC
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -147,6 +147,6 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
#endif // QT_POSIX_IPC
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#ifndef QT_POSIX_IPC
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
|
|
@ -72,7 +72,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
|
|||
}
|
||||
createdFile = (1 == built);
|
||||
|
||||
#if !defined(QT_NO_SHAREDMEMORY) && !defined(QT_POSIX_IPC) && !defined(Q_OS_ANDROID)
|
||||
#if QT_CONFIG(sharedmemory) && !defined(QT_POSIX_IPC) && !defined(Q_OS_ANDROID)
|
||||
// Get the unix key for the created file
|
||||
unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q');
|
||||
#endif
|
||||
|
|
@ -185,6 +185,6 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
#endif // QT_POSIX_IPC
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <qdebug.h>
|
||||
#include <qcoreapplication.h>
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef QT_POSIX_IPC
|
||||
|
|
@ -70,4 +70,4 @@ void QSystemSemaphorePrivate::setErrorString(const QString &function)
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
#ifndef QT_NO_SYSTEMSEMAPHORE
|
||||
#if QT_CONFIG(systemsemaphore)
|
||||
|
||||
QSystemSemaphorePrivate::QSystemSemaphorePrivate() :
|
||||
semaphore(0), error(QSystemSemaphore::NoError)
|
||||
|
|
@ -97,6 +97,6 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
|
|||
return true;
|
||||
}
|
||||
|
||||
#endif //QT_NO_SYSTEMSEMAPHORE
|
||||
#endif // QT_CONFIG(systemsemaphore)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue