From 4c324c1b19af9b67a13403512497b7c6e46e8a02 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 13 May 2019 14:12:13 +0200 Subject: [PATCH] Fixed semaphore problems on MacOS --- lib/defines.h | 4 ++-- lib/shared_memory.cpp | 8 ++++++++ lib/stream.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 194dc821..1da61b19 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -46,9 +46,9 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", " #endif #else #if DEBUG >= DLVL_DEVEL -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, __LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|MistProcess|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, __LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__);} #else -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), Util::Config::streamName.c_str(), ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|MistProcess|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), Util::Config::streamName.c_str(), ##__VA_ARGS__);} #endif #endif diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index fafbccd7..af973fe5 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -121,6 +121,14 @@ namespace IPC { #else if (oflag & O_CREAT) { mySem = sem_open(name, oflag, mode, value); +#if defined(__APPLE__) + if (!(*this)){ + if (sem_unlink(name) == 0){ + INFO_MSG("Deleted in-use semaphore: %s", name); + mySem = sem_open(name, oflag, mode, value); + } + } +#endif } else { mySem = sem_open(name, oflag); } diff --git a/lib/stream.cpp b/lib/stream.cpp index 5e6360b9..adb012ab 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -125,7 +125,7 @@ DTSC::Meta Util::getStreamMeta(const std::string &streamname){ bool Util::streamAlive(std::string &streamname){ char semName[NAME_BUFFER_SIZE]; snprintf(semName, NAME_BUFFER_SIZE, SEM_INPUT, streamname.c_str()); - IPC::semaphore playerLock(semName, O_RDWR, ACCESSPERMS, 1, true); + IPC::semaphore playerLock(semName, O_RDWR, ACCESSPERMS, 0, true); if (!playerLock){return false;} if (!playerLock.tryWait()){ playerLock.close();