Explicitly stop the RPCWorker in RPCServer destructor
This commit is contained in:
parent
32219cf0a3
commit
18a4d66903
12
src/rpc.cpp
12
src/rpc.cpp
|
@ -59,8 +59,7 @@ RPCWorker::RPCWorker() {
|
|||
}
|
||||
|
||||
RPCWorker::~RPCWorker() {
|
||||
m_stop = true;
|
||||
m_thread.join();
|
||||
stop();
|
||||
}
|
||||
|
||||
void RPCWorker::add_task(std::function<json()> 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();
|
||||
|
|
|
@ -46,6 +46,7 @@ class RPCWorker {
|
|||
void add_task(std::function<json()>);
|
||||
json pop_task_result();
|
||||
void try_run_task();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
bool m_stop = false;
|
||||
|
|
Loading…
Reference in New Issue