From 6a4901db257d1099e07fce92731e34155417385b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 27 Mar 2023 21:16:57 -0600 Subject: [PATCH] IPC: QSystemSemaphore/SystemV: move up the check for handle This avoids recalculating the native key file name every time we call handle() to ensure the handle exists. The POSIX backend already has the code like this (whence the comment was copied) and the Win32 backend is similar. Change-Id: Idd5e1bb52be047d7b4fffffd175076ec09334ae1 Reviewed-by: Thiago Macieira Reviewed-by: Fabian Kosmale --- src/corelib/ipc/qsystemsemaphore_systemv.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/ipc/qsystemsemaphore_systemv.cpp b/src/corelib/ipc/qsystemsemaphore_systemv.cpp index cdfa6adfd4..e976fa5e09 100644 --- a/src/corelib/ipc/qsystemsemaphore_systemv.cpp +++ b/src/corelib/ipc/qsystemsemaphore_systemv.cpp @@ -53,6 +53,9 @@ bool QSystemSemaphoreSystemV::runtimeSupportCheck() */ key_t QSystemSemaphoreSystemV::handle(QSystemSemaphorePrivate *self, QSystemSemaphore::AccessMode mode) { + if (unix_key != -1) + return unix_key; // we already have a semaphore + #if defined(Q_OS_DARWIN) if (qt_apple_isSandboxed()) { // attempting to use System V semaphores will get us a SIGSYS @@ -73,9 +76,6 @@ key_t QSystemSemaphoreSystemV::handle(QSystemSemaphorePrivate *self, QSystemSema return -1; } - if (-1 != unix_key) - return unix_key; - // ftok requires that an actual file exists somewhere int built = QtIpcCommon::createUnixKeyFile(nativeKeyFile); if (-1 == built) {