diff options
Diffstat (limited to 'src/corelib/ipc/qsharedmemory.cpp')
-rw-r--r-- | src/corelib/ipc/qsharedmemory.cpp | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/corelib/ipc/qsharedmemory.cpp b/src/corelib/ipc/qsharedmemory.cpp index 9e33b1d995..02761c0263 100644 --- a/src/corelib/ipc/qsharedmemory.cpp +++ b/src/corelib/ipc/qsharedmemory.cpp @@ -7,6 +7,7 @@ #include "qtipccommon_p.h" #include "qsystemsemaphore.h" +#include <q20memory.h> #include <qdebug.h> #ifdef Q_OS_WIN # include <qt_windows.h> @@ -23,15 +24,6 @@ QT_BEGIN_NAMESPACE using namespace QtIpcCommon; using namespace Qt::StringLiterals; -#if __cplusplus >= 202002L -using std::construct_at; -#else -template <typename T> static void construct_at(T *ptr) -{ - new (ptr) T; -} -#endif - QSharedMemoryPrivate::~QSharedMemoryPrivate() { destructBackend(); @@ -39,6 +31,7 @@ QSharedMemoryPrivate::~QSharedMemoryPrivate() inline void QSharedMemoryPrivate::constructBackend() { + using namespace q20; visit([](auto p) { construct_at(p); }); } @@ -132,24 +125,17 @@ QSharedMemory::QSharedMemory(const QNativeIpcKey &key, QObject *parent) setNativeKey(key); } -#if QT_DEPRECATED_SINCE(6, 10) /*! - \deprecated - Constructs a shared memory object with the given \a parent and with the legacy key set to \a key. Because its key is set, its create() and attach() functions can be called. - Legacy keys are deprecated. See \l{Native IPC Keys} for more information. - \sa setKey(), create(), attach() */ QSharedMemory::QSharedMemory(const QString &key, QObject *parent) : QSharedMemory(legacyNativeKey(key), parent) { - d_func()->legacyKey = key; } -#endif /*! The destructor clears the key, which forces the shared memory object @@ -168,9 +154,7 @@ QSharedMemory::~QSharedMemory() d->cleanHandle(); } -#if QT_DEPRECATED_SINCE(6, 10) /*! - \deprecated \overload Sets the legacy \a key for this shared memory object. If \a key is the same @@ -192,11 +176,8 @@ QSharedMemory::~QSharedMemory() */ void QSharedMemory::setKey(const QString &key) { - Q_D(QSharedMemory); setNativeKey(legacyNativeKey(key)); - d->legacyKey = key; } -#endif /*! \since 4.8 @@ -252,7 +233,6 @@ void QSharedMemory::setNativeKey(const QNativeIpcKey &key) if (isAttached()) detach(); d->cleanHandle(); - d->legacyKey = QString(); if (key.type() == d->nativeKey.type()) { // we can reuse the backend d->nativeKey = key; @@ -269,7 +249,11 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) if (!cleanHandle()) return false; #if QT_CONFIG(systemsemaphore) - systemSemaphore.setNativeKey(semaphoreNativeKey(), 1, mode); + const QString legacyKey = QNativeIpcKeyPrivate::legacyKey(nativeKey); + const QNativeIpcKey semKey = legacyKey.isEmpty() + ? semaphoreNativeKey() + : QSystemSemaphore::legacyNativeKey(legacyKey, nativeKey.type()); + systemSemaphore.setNativeKey(semKey, 1, mode); if (systemSemaphore.error() != QSystemSemaphore::NoError) { QString function = "QSharedMemoryPrivate::initKey"_L1; errorString = QSharedMemory::tr("%1: unable to set key on lock (%2)") @@ -305,9 +289,7 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) return true; } -#if QT_DEPRECATED_SINCE(6, 10) /*! - \deprecated Returns the legacy key assigned with setKey() to this shared memory, or a null key if no key has been assigned, or if the segment is using a nativeKey(). The key is the identifier used by Qt applications to identify the shared memory @@ -321,9 +303,8 @@ bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode mode) QString QSharedMemory::key() const { Q_D(const QSharedMemory); - return d->legacyKey; + return QNativeIpcKeyPrivate::legacyKey(d->nativeKey); } -#endif /*! \since 4.8 @@ -693,12 +674,12 @@ bool QSharedMemory::isKeyTypeSupported(QNativeIpcKey::Type type) QNativeIpcKey QSharedMemory::platformSafeKey(const QString &key, QNativeIpcKey::Type type) { - return { QtIpcCommon::platformSafeKey(key, IpcType::SharedMemory, type), type }; + return QtIpcCommon::platformSafeKey(key, IpcType::SharedMemory, type); } QNativeIpcKey QSharedMemory::legacyNativeKey(const QString &key, QNativeIpcKey::Type type) { - return { legacyPlatformSafeKey(key, IpcType::SharedMemory, type), type }; + return QtIpcCommon::legacyPlatformSafeKey(key, IpcType::SharedMemory, type); } #endif // QT_CONFIG(sharedmemory) |