mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-08-19 13:08:46 -06:00
Fixed libuv init/shutdown sequence
This commit is contained in:
parent
53ba29b288
commit
d0eea1bf91
@ -93,12 +93,20 @@ else()
|
|||||||
include_directories(external/src/curl/include)
|
include_directories(external/src/curl/include)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if ((CMAKE_CXX_COMPILER_ID MATCHES MSVC) OR STATIC_BINARY OR STATIC_LIBS)
|
||||||
|
set(UV_INCLUDE_DIR external/src/libuv/include)
|
||||||
|
set(ZMQ_INCLUDE_DIR external/src/libzmq/include)
|
||||||
|
else()
|
||||||
|
find_path(UV_INCLUDE_DIR NAMES uv.h PATH_SUFFIXES "include")
|
||||||
|
find_path(ZMQ_INCLUDE_DIR NAMES zmq.h PATH_SUFFIXES "include")
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories(src)
|
include_directories(src)
|
||||||
include_directories(external/src)
|
include_directories(external/src)
|
||||||
include_directories(external/src/cryptonote)
|
include_directories(external/src/cryptonote)
|
||||||
include_directories(external/src/libuv/include)
|
include_directories(${UV_INCLUDE_DIR})
|
||||||
include_directories(external/src/cppzmq)
|
include_directories(external/src/cppzmq)
|
||||||
include_directories(external/src/libzmq/include)
|
include_directories(${ZMQ_INCLUDE_DIR})
|
||||||
if (WITH_RANDOMX)
|
if (WITH_RANDOMX)
|
||||||
include_directories(external/src/RandomX/src)
|
include_directories(external/src/RandomX/src)
|
||||||
endif()
|
endif()
|
||||||
|
40
src/log.cpp
40
src/log.cpp
@ -64,6 +64,7 @@ public:
|
|||||||
|
|
||||||
// Create default loop here
|
// Create default loop here
|
||||||
uv_default_loop();
|
uv_default_loop();
|
||||||
|
init_uv_threadpool();
|
||||||
|
|
||||||
uv_cond_init(&m_cond);
|
uv_cond_init(&m_cond);
|
||||||
uv_mutex_init(&m_mutex);
|
uv_mutex_init(&m_mutex);
|
||||||
@ -115,6 +116,10 @@ public:
|
|||||||
uv_mutex_destroy(&m_mutex);
|
uv_mutex_destroy(&m_mutex);
|
||||||
uv_loop_close(uv_default_loop());
|
uv_loop_close(uv_default_loop());
|
||||||
|
|
||||||
|
#if ((UV_VERSION_MAJOR > 1) || ((UV_VERSION_MAJOR == 1) && (UV_VERSION_MINOR >= 38)))
|
||||||
|
uv_library_shutdown();
|
||||||
|
#endif
|
||||||
|
|
||||||
m_logFile.close();
|
m_logFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +148,33 @@ public:
|
|||||||
uv_cond_signal(&m_cond);
|
uv_cond_signal(&m_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void init_uv_threadpool()
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define putenv _putenv
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint32_t N = std::max(std::min(std::thread::hardware_concurrency(), 4U), 8U);
|
||||||
|
LOGINFO(4, "running " << N << " threads in the UV thread pool");
|
||||||
|
|
||||||
|
char buf[40] = {};
|
||||||
|
log::Stream s(buf);
|
||||||
|
s << "UV_THREADPOOL_SIZE=" << N << '\0';
|
||||||
|
|
||||||
|
int err = putenv(buf);
|
||||||
|
if (err != 0) {
|
||||||
|
err = errno;
|
||||||
|
LOGWARN(1, "Couldn't set UV thread pool size to " << N << " threads, putenv returned error " << err);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uv_work_t dummy;
|
||||||
|
err = uv_queue_work(uv_default_loop_checked(), &dummy, [](uv_work_t*) {}, nullptr);
|
||||||
|
if (err) {
|
||||||
|
LOGERR(1, "init_uv_threadpool: uv_queue_work failed, error " << uv_err_name(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void run_wrapper(void* arg) { reinterpret_cast<Worker*>(arg)->run(); }
|
static void run_wrapper(void* arg) { reinterpret_cast<Worker*>(arg)->run(); }
|
||||||
|
|
||||||
@ -153,7 +185,11 @@ private:
|
|||||||
do {
|
do {
|
||||||
uv_mutex_lock(&m_mutex);
|
uv_mutex_lock(&m_mutex);
|
||||||
if (m_readPos == m_writePos.load()) {
|
if (m_readPos == m_writePos.load()) {
|
||||||
// Nothing to do, wait for the signal
|
// Nothing to do, wait for the signal or exit if stopped
|
||||||
|
if (stopped) {
|
||||||
|
uv_mutex_unlock(&m_mutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
uv_cond_wait(&m_cond, &m_mutex);
|
uv_cond_wait(&m_cond, &m_mutex);
|
||||||
}
|
}
|
||||||
uv_mutex_unlock(&m_mutex);
|
uv_mutex_unlock(&m_mutex);
|
||||||
@ -231,7 +267,7 @@ private:
|
|||||||
m_logFile.open(log_file_name, std::ios::app | std::ios::binary);
|
m_logFile.open(log_file_name, std::ios::app | std::ios::binary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!stopped);
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCEINLINE void strip_colors(char* buf, uint32_t& size)
|
static FORCEINLINE void strip_colors(char* buf, uint32_t& size)
|
||||||
|
@ -1442,29 +1442,6 @@ static void on_signal(uv_signal_t* handle, int signum)
|
|||||||
pool->stop();
|
pool->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool init_uv_threadpool()
|
|
||||||
{
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define putenv _putenv
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint32_t N = std::max(std::min(std::thread::hardware_concurrency(), 4U), 8U);
|
|
||||||
LOGINFO(4, "running " << N << " threads in the UV thread pool");
|
|
||||||
|
|
||||||
char buf[40] = {};
|
|
||||||
log::Stream s(buf);
|
|
||||||
s << "UV_THREADPOOL_SIZE=" << N << '\0';
|
|
||||||
|
|
||||||
int err = putenv(buf);
|
|
||||||
if (err != 0) {
|
|
||||||
err = errno;
|
|
||||||
LOGWARN(1, "Couldn't set UV thread pool size to " << N << " threads, putenv returned error " << err);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uv_work_t dummy;
|
|
||||||
return (uv_queue_work(uv_default_loop_checked(), &dummy, [](uv_work_t*) {}, nullptr) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool init_signals(p2pool* pool, bool init)
|
bool init_signals(p2pool* pool, bool init)
|
||||||
{
|
{
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
@ -1549,11 +1526,6 @@ int p2pool::run()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!init_uv_threadpool()) {
|
|
||||||
LOGERR(1, "failed to start UV thread pool");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!init_signals(this, true)) {
|
if (!init_signals(this, true)) {
|
||||||
LOGERR(1, "failed to initialize signal handlers");
|
LOGERR(1, "failed to initialize signal handlers");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -55,13 +55,30 @@ set(SOURCES
|
|||||||
../src/zmq_reader.cpp
|
../src/zmq_reader.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (NOT STATIC_BINARY AND NOT STATIC_LIBS)
|
||||||
|
include(FindCURL)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CURL_INCLUDE_DIRS)
|
||||||
|
include_directories(${CURL_INCLUDE_DIRS})
|
||||||
|
else()
|
||||||
|
include_directories(../external/src/curl/include)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if ((CMAKE_CXX_COMPILER_ID MATCHES MSVC) OR STATIC_BINARY OR STATIC_LIBS)
|
||||||
|
set(UV_INCLUDE_DIR ../external/src/libuv/include)
|
||||||
|
set(ZMQ_INCLUDE_DIR ../external/src/libzmq/include)
|
||||||
|
else()
|
||||||
|
find_path(UV_INCLUDE_DIR NAMES uv.h PATH_SUFFIXES "include")
|
||||||
|
find_path(ZMQ_INCLUDE_DIR NAMES zmq.h PATH_SUFFIXES "include")
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories(../src)
|
include_directories(../src)
|
||||||
include_directories(../external/src)
|
include_directories(../external/src)
|
||||||
include_directories(../external/src/cryptonote)
|
include_directories(../external/src/cryptonote)
|
||||||
include_directories(../external/src/curl/include)
|
include_directories(${UV_INCLUDE_DIR})
|
||||||
include_directories(../external/src/libuv/include)
|
|
||||||
include_directories(../external/src/cppzmq)
|
include_directories(../external/src/cppzmq)
|
||||||
include_directories(../external/src/libzmq/include)
|
include_directories(${ZMQ_INCLUDE_DIR})
|
||||||
include_directories(../external/src/RandomX/src)
|
include_directories(../external/src/RandomX/src)
|
||||||
include_directories(../external/src/rapidjson/include)
|
include_directories(../external/src/rapidjson/include)
|
||||||
include_directories(../external/src/robin-hood-hashing/src/include)
|
include_directories(../external/src/robin-hood-hashing/src/include)
|
||||||
|
Loading…
Reference in New Issue
Block a user