mirror of
https://github.com/AxioDL/logvisor.git
synced 2025-12-09 21:48:06 +00:00
Better regulation of logging mutex
This commit is contained in:
@@ -87,14 +87,29 @@ extern std::atomic_uint_fast64_t FrameIndex;
|
||||
*
|
||||
* Ensures logging streams aren't written concurrently
|
||||
*/
|
||||
extern std::recursive_mutex LogMutex;
|
||||
struct LogMutex
|
||||
{
|
||||
bool enabled = true;
|
||||
std::recursive_mutex mutex;
|
||||
~LogMutex() { enabled = false; }
|
||||
std::unique_lock<std::recursive_mutex> lock()
|
||||
{
|
||||
if (enabled)
|
||||
return std::unique_lock<std::recursive_mutex>(mutex);
|
||||
else
|
||||
return std::unique_lock<std::recursive_mutex>();
|
||||
}
|
||||
};
|
||||
extern LogMutex _LogMutex;
|
||||
|
||||
/**
|
||||
* @brief Take a centralized lock for the logging output stream(s)
|
||||
* @return RAII mutex lock
|
||||
*/
|
||||
static inline std::unique_lock<std::recursive_mutex> LockLog()
|
||||
{return std::unique_lock<std::recursive_mutex>{LogMutex};}
|
||||
{
|
||||
return _LogMutex.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Restore centralized logger vector to default state (silent operation)
|
||||
|
||||
Reference in New Issue
Block a user