mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Logger fixes
- Fixed a race condition when stopping the logger - Flush log file only once per batch of log lines
This commit is contained in:
parent
094209f311
commit
9e287ab4f0
1 changed files with 7 additions and 4 deletions
11
src/log.cpp
11
src/log.cpp
|
@ -32,7 +32,7 @@ bool CONSOLE_COLORS = true;
|
|||
|
||||
#ifndef P2POOL_LOG_DISABLE
|
||||
|
||||
static volatile bool stopped = false;
|
||||
static std::atomic<bool> stopped{ false };
|
||||
static volatile bool worker_started = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -102,11 +102,10 @@ public:
|
|||
|
||||
FORCEINLINE void stop()
|
||||
{
|
||||
if (stopped) {
|
||||
if (stopped.exchange(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopped = true;
|
||||
LOGINFO(0, "stopped");
|
||||
uv_thread_join(&m_worker);
|
||||
uv_cond_destroy(&m_cond);
|
||||
|
@ -208,7 +207,6 @@ private:
|
|||
}
|
||||
|
||||
m_logFile.write(p, size);
|
||||
m_logFile.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,6 +216,11 @@ private:
|
|||
m_readPos += SLOT_SIZE;
|
||||
} while (m_readPos < writePos);
|
||||
}
|
||||
|
||||
// Flush the log file only after all pending log lines have been written
|
||||
if (m_logFile.is_open()) {
|
||||
m_logFile.flush();
|
||||
}
|
||||
} while (!stopped);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue