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" 52 std::string name =
"Local\\QuillLock" + pid;
55 _handle = CreateMutexA(
nullptr, TRUE, name.data());
57 if (_handle ==
nullptr)
59 QUILL_THROW(
QuillError{
"Failed to create mutex"});
62 if (GetLastError() == ERROR_ALREADY_EXISTS)
66 "Duplicate backend worker thread detected. This indicates that the logging library has " 67 "been compiled into multiple binary modules (for instance, one module using a static build " 68 "and another using a shared build), resulting in separate instances of the backend worker. " 69 "Please build and link the logging library uniformly as a shared library with exported " 70 "symbols to ensure a single backend instance."});
72 #elif defined(__ANDROID__) 75 std::string name =
"/QuillLock" + pid;
79 _sem = sem_open(name.data(), O_CREAT, 0644, 1);
80 if (_sem == SEM_FAILED)
82 QUILL_THROW(
QuillError{
"Failed to create semaphore - errno: " + std::to_string(errno) +
83 " error: " + strerror(errno)});
88 sem_unlink(name.data());
93 if (sem_trywait(_sem) != 0)
96 "Duplicate backend worker thread detected. This indicates that the logging library has " 97 "been compiled into multiple binary modules (for instance, one module using a static build " 98 "and another using a shared build), resulting in separate instances of the backend worker. " 99 "Please build and link the logging library uniformly as a shared library with exported " 100 "symbols to ensure a single backend instance."});
109 if (_handle !=
nullptr)
111 ReleaseMutex(_handle);
112 CloseHandle(_handle);
116 if (_sem != SEM_FAILED)
131 HANDLE _handle{
nullptr};
133 sem_t* _sem{SEM_FAILED};
Ensures that only one instance of the backend worker is active.
Definition: BackendWorkerLock.h:45
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
custom exception
Definition: QuillError.h:45