10 #if !defined(WIN32_LEAN_AND_MEAN) 11 #define WIN32_LEAN_AND_MEAN 14 #if !defined(NOMINMAX) 20 #elif defined(__ANDROID__) 30 #include "quill/core/Attributes.h" 31 #include "quill/core/QuillError.h" 32 #include "quill/core/ThreadPrimitives.h" 61 std::string name =
"Local\\QuillBackendLock" + pid;
64 _handle = CreateMutexA(
nullptr, TRUE, name.data());
66 if (_handle ==
nullptr)
68 QUILL_THROW(
QuillError{
"Failed to create mutex '" + name +
"'"});
71 if (GetLastError() == ERROR_ALREADY_EXISTS)
78 "Duplicate backend worker thread detected. This indicates that the logging library has " 79 "been compiled into multiple binary modules (for instance, one module using a static build " 80 "and another using a shared build), resulting in separate instances of the backend worker. " 81 "Please build and link the logging library uniformly as a shared library with exported " 82 "symbols to ensure a single backend instance."});
84 #elif defined(__ANDROID__) 87 std::string path =
"/tmp/QuillBackendLock" + pid;
92 constexpr
int max_retries{3};
93 constexpr uint64_t retry_delay_ns{100000000};
96 for (
int attempt = 0; attempt < max_retries; ++attempt)
100 fd = open(path.data(), O_CREAT | O_RDWR, 0644);
101 }
while (fd == -1 && errno == EINTR);
108 if (attempt < max_retries - 1)
128 for (
int attempt = 0; attempt < max_retries; ++attempt)
133 ret = flock(_fd, LOCK_EX | LOCK_NB);
134 }
while (ret != 0 && errno == EINTR);
144 if (flock_err == EWOULDBLOCK)
150 if (attempt < max_retries - 1)
161 if (flock_err == EWOULDBLOCK)
164 "Duplicate backend worker thread detected. This indicates that the logging library has " 165 "been compiled into multiple binary modules (for instance, one module using a static " 167 "and another using a shared build), resulting in separate instances of the backend " 169 "Please build and link the logging library uniformly as a shared library with exported " 170 "symbols to ensure a single backend instance."});
184 if (_handle !=
nullptr)
186 ReleaseMutex(_handle);
187 CloseHandle(_handle);
190 #elif defined(__ANDROID__) 198 unlink(_path.data());
213 HANDLE _handle{
nullptr};
214 #elif defined(__ANDROID__) QUILL_ATTRIBUTE_HOT void sleep_for_ns(uint64_t ns) noexcept
Mirrors std::this_thread::sleep_for(std::chrono::nanoseconds{ns}).
Definition: ThreadPrimitives.h:43
Ensures that only one instance of the backend worker is active.
Definition: BackendWorkerLock.h:54
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:28
custom exception
Definition: QuillError.h:47