mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Fixed logger thread start/stop logic
This commit is contained in:
parent
4d16c77f73
commit
2f08a35ac7
1 changed files with 9 additions and 0 deletions
|
@ -31,6 +31,7 @@ namespace log {
|
||||||
int GLOBAL_LOG_LEVEL = 5;
|
int GLOBAL_LOG_LEVEL = 5;
|
||||||
|
|
||||||
static volatile bool stopped = false;
|
static volatile bool stopped = false;
|
||||||
|
static volatile bool worker_started = false;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static const HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
static const HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
@ -61,6 +62,8 @@ public:
|
||||||
uv_mutex_init(&m_mutex);
|
uv_mutex_init(&m_mutex);
|
||||||
uv_thread_create(&m_worker, run_wrapper, this);
|
uv_thread_create(&m_worker, run_wrapper, this);
|
||||||
|
|
||||||
|
do {} while (!worker_started);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD dwConsoleMode;
|
DWORD dwConsoleMode;
|
||||||
if (GetConsoleMode(hStdOut, &dwConsoleMode)) {
|
if (GetConsoleMode(hStdOut, &dwConsoleMode)) {
|
||||||
|
@ -82,6 +85,10 @@ public:
|
||||||
|
|
||||||
FORCEINLINE void stop()
|
FORCEINLINE void stop()
|
||||||
{
|
{
|
||||||
|
if (stopped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
LOGINFO(0, "stopped");
|
LOGINFO(0, "stopped");
|
||||||
uv_thread_join(&m_worker);
|
uv_thread_join(&m_worker);
|
||||||
|
@ -121,6 +128,8 @@ private:
|
||||||
|
|
||||||
NOINLINE void run()
|
NOINLINE void run()
|
||||||
{
|
{
|
||||||
|
worker_started = true;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
uv_mutex_lock(&m_mutex);
|
uv_mutex_lock(&m_mutex);
|
||||||
uv_cond_wait(&m_cond, &m_mutex);
|
uv_cond_wait(&m_cond, &m_mutex);
|
||||||
|
|
Loading…
Reference in a new issue