From fb73b81b984bf602ce2f2eaa0f25da2ae252c9e9 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 4 Dec 2019 11:39:17 +0100 Subject: [PATCH] Change EventLoop::m_task_set to not use boost EventLoop::m_task_set was unnecessary defined as boost::optional because it is always initialized. It can, however, possibly be destroyed twice: in the EventLoop::loop() method (conditional) and in the EventLoop destructor when it goes out of scope (unconditional). So, use std::unique_ptr to handle this. --- include/mp/proxy-io.h | 3 ++- src/mp/proxy.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h index 1e27f96..e74a5ee 100644 --- a/include/mp/proxy-io.h +++ b/include/mp/proxy-io.h @@ -15,6 +15,7 @@ #include #include +#include #include namespace mp { @@ -199,7 +200,7 @@ class EventLoop LoggingErrorHandler m_error_handler{*this}; //! Capnp list of pending promises. - boost::optional m_task_set; + std::unique_ptr m_task_set; //! List of connections. std::list m_incoming_connections; diff --git a/src/mp/proxy.cpp b/src/mp/proxy.cpp index 8b0c2b0..e1ae9b8 100644 --- a/src/mp/proxy.cpp +++ b/src/mp/proxy.cpp @@ -123,13 +123,16 @@ void Connection::addAsyncCleanup(std::function fn) } EventLoop::EventLoop(const char* exe_name, LogFn log_fn, void* context) - : m_exe_name(exe_name), m_io_context(kj::setupAsyncIo()), m_log_fn(std::move(log_fn)), m_context(context) + : m_exe_name(exe_name), + m_io_context(kj::setupAsyncIo()), + m_log_fn(std::move(log_fn)), + m_context(context), + m_task_set(new kj::TaskSet(m_error_handler)) { int fds[2]; KJ_SYSCALL(socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); m_wait_fd = fds[0]; m_post_fd = fds[1]; - m_task_set.emplace(m_error_handler); } EventLoop::~EventLoop()