mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-08 19:59:30 +00:00
TCPServer: check if loop thread is running before waiting for it
This commit is contained in:
parent
fcb62894a5
commit
8a222d5e75
2 changed files with 8 additions and 1 deletions
|
@ -27,6 +27,7 @@ TCPServer::TCPServer(int default_backlog, allocate_client_callback allocate_new_
|
|||
: m_allocateNewClient(allocate_new_client)
|
||||
, m_defaultBacklog(default_backlog)
|
||||
, m_loopThread{}
|
||||
, m_loopThreadRunning(false)
|
||||
#ifdef WITH_UPNP
|
||||
, m_portMapping(0)
|
||||
#endif
|
||||
|
@ -473,7 +474,9 @@ void TCPServer::shutdown_tcp()
|
|||
}
|
||||
#endif
|
||||
|
||||
uv_thread_join(&m_loopThread);
|
||||
if (m_loopThreadRunning.load()) {
|
||||
uv_thread_join(&m_loopThread);
|
||||
}
|
||||
|
||||
uv_mutex_destroy(&m_bansLock);
|
||||
|
||||
|
@ -573,6 +576,9 @@ bool TCPServer::send_internal(Client* client, Callback<size_t, uint8_t*, size_t>
|
|||
void TCPServer::loop(void* data)
|
||||
{
|
||||
TCPServer* server = static_cast<TCPServer*>(data);
|
||||
server->m_loopThreadRunning.exchange(true);
|
||||
ON_SCOPE_LEAVE([server]() { server->m_loopThreadRunning.exchange(false); });
|
||||
|
||||
log_category_prefix = server->get_category();
|
||||
|
||||
LOGINFO(1, "event loop started");
|
||||
|
|
|
@ -149,6 +149,7 @@ protected:
|
|||
int m_defaultBacklog;
|
||||
|
||||
uv_thread_t m_loopThread;
|
||||
std::atomic<bool> m_loopThreadRunning;
|
||||
|
||||
static void loop(void* data);
|
||||
|
||||
|
|
Loading…
Reference in a new issue