From 18a4d669031ae58bb98d14dfb1d1c5467cfb5ec8 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Tue, 3 May 2016 12:05:58 -0700 Subject: [PATCH] Explicitly stop the RPCWorker in RPCServer destructor --- src/rpc.cpp | 12 ++++++++++-- src/rpc.hpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rpc.cpp b/src/rpc.cpp index 81f14b0d..dd1fe422 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -59,8 +59,7 @@ RPCWorker::RPCWorker() { } RPCWorker::~RPCWorker() { - m_stop = true; - m_thread.join(); + stop(); } void RPCWorker::add_task(std::function task) { @@ -89,6 +88,13 @@ void RPCWorker::try_run_task() { } } +void RPCWorker::stop() { + if (!m_stop) { + m_stop = true; + m_thread.join(); + } +} + RPCServer::RPCServer() { m_context = JSGlobalContextCreate(NULL); get_rpc_server(m_context) = this; @@ -190,6 +196,8 @@ RPCServer::RPCServer() { } RPCServer::~RPCServer() { + m_worker.stop(); + // The protected values should be unprotected before releasing the context. m_objects.clear(); m_callbacks.clear(); diff --git a/src/rpc.hpp b/src/rpc.hpp index a74db8d0..4fe333b7 100644 --- a/src/rpc.hpp +++ b/src/rpc.hpp @@ -46,6 +46,7 @@ class RPCWorker { void add_task(std::function); json pop_task_result(); void try_run_task(); + void stop(); private: bool m_stop = false;