10 #if !defined(WIN32_LEAN_AND_MEAN) 11 #define WIN32_LEAN_AND_MEAN 14 #if !defined(NOMINMAX) 23 #include <semaphore.h> 26 #include "quill/core/Attributes.h" 27 #include "quill/core/QuillError.h" 53 std::string name =
"Local\\QuillLock" + pid;
56 _handle = CreateMutexA(
nullptr, TRUE, name.data());
58 if (_handle ==
nullptr)
60 QUILL_THROW(
QuillError{
"Failed to create mutex"});
63 if (GetLastError() == ERROR_ALREADY_EXISTS)
67 "Duplicate backend worker thread detected. This indicates that the logging library has " 68 "been compiled into multiple binary modules (for instance, one module using a static build " 69 "and another using a shared build), resulting in separate instances of the backend worker. " 70 "Please build and link the logging library uniformly as a shared library with exported " 71 "symbols to ensure a single backend instance."});
73 #elif defined(__ANDROID__) 76 std::string name =
"/QuillLock" + pid;
80 _sem = sem_open(name.data(), O_CREAT, 0644, 1);
81 if (_sem == SEM_FAILED)
83 QUILL_THROW(
QuillError{
"Failed to create semaphore - errno: " + std::to_string(errno) +
84 " error: " + std::strerror(errno)});
89 sem_unlink(name.data());
94 if (sem_trywait(_sem) != 0)
97 "Duplicate backend worker thread detected. This indicates that the logging library has " 98 "been compiled into multiple binary modules (for instance, one module using a static build " 99 "and another using a shared build), resulting in separate instances of the backend worker. " 100 "Please build and link the logging library uniformly as a shared library with exported " 101 "symbols to ensure a single backend instance."});
110 if (_handle !=
nullptr)
112 ReleaseMutex(_handle);
113 CloseHandle(_handle);
117 if (_sem != SEM_FAILED)
132 HANDLE _handle{
nullptr};
134 sem_t* _sem{SEM_FAILED};
Ensures that only one instance of the backend worker is active.
Definition: BackendWorkerLock.h:46
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
custom exception
Definition: QuillError.h:45