From ae9d15c977f1394f5783dd76dadaa407031bbd28 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 6 Aug 2021 09:59:35 -0700 Subject: [PATCH] Mac/iOS fixes Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../Platform/Mac/AzCore/IPC/SharedMemory_Mac.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Code/Framework/AzCore/Platform/Mac/AzCore/IPC/SharedMemory_Mac.cpp b/Code/Framework/AzCore/Platform/Mac/AzCore/IPC/SharedMemory_Mac.cpp index 5555704040..5b2d2af34f 100644 --- a/Code/Framework/AzCore/Platform/Mac/AzCore/IPC/SharedMemory_Mac.cpp +++ b/Code/Framework/AzCore/Platform/Mac/AzCore/IPC/SharedMemory_Mac.cpp @@ -29,20 +29,19 @@ namespace AZ return errno; } - void ComposeMutexName(char* dest, size_t length, const char* name) + void ComposeName(char* dest, size_t length, const char* name, const char* suffix) { - azstrncpy(m_name, AZ_ARRAY_SIZE(m_name), name, strlen(name)); - // sem_open doesn't support paths bigger than 31, so call it s_Mtx. // While this is enough for Profiler, maybe the code should be smarter // and trim the name instead - azsnprintf(dest, length, "/tmp/%s_Mtx", name); + azsnprintf(dest, length, "/tmp/%s_%s", name, suffix); } SharedMemory_Common::CreateResult SharedMemory_Mac::Create(const char* name, unsigned int size, bool openIfCreated) { char fullName[256]; - ComposeMutexName(fullName, AZ_ARRAY_SIZE(fullName), name); + azstrncpy(m_name, AZ_ARRAY_SIZE(m_name), name, strlen(name)); + ComposeName(fullName, AZ_ARRAY_SIZE(fullName), name, "Mtx"); m_globalMutex = sem_open(fullName, O_CREAT | O_EXCL, 0600, 1); int error = errno; @@ -59,7 +58,7 @@ namespace AZ } // Create the file mapping. - azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name); + ComposeName(fullName, AZ_ARRAY_SIZE(fullName), name, "Data"); m_mapHandle = shm_open(fullName, O_RDWR | O_CREAT | O_EXCL, 0600); error = errno; if (error == EEXIST) @@ -80,7 +79,8 @@ namespace AZ bool SharedMemory_Mac::Open(const char* name) { char fullName[256]; - ComposeMutexName(fullName, AZ_ARRAY_SIZE(fullName), name); + azstrncpy(m_name, AZ_ARRAY_SIZE(m_name), name, strlen(name)); + ComposeName(fullName, AZ_ARRAY_SIZE(fullName), name, "Mtx"); m_globalMutex = sem_open(fullName, 0); AZ_Warning("AZSystem", m_globalMutex != nullptr, "Failed to open OS mutex [%s]\n", m_name); @@ -90,7 +90,7 @@ namespace AZ return false; } - azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name); + ComposeName(fullName, AZ_ARRAY_SIZE(fullName), name, "Data"); m_mapHandle = shm_open(fullName, O_RDWR, 0600); if (m_mapHandle == -1) {