Skip to content

Commit

Permalink
Change EventLoop::m_task_set to not use boost
Browse files Browse the repository at this point in the history
EventLoop::m_task_set was unnecessary defined as
boost::optional<kj::TaskSet> 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.
  • Loading branch information
vasild authored and ryanofsky committed Jan 6, 2020
1 parent 138ad67 commit fb73b81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/mp/proxy-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <capnp/rpc-twoparty.h>

#include <functional>
#include <memory>
#include <string>

namespace mp {
Expand Down Expand Up @@ -199,7 +200,7 @@ class EventLoop
LoggingErrorHandler m_error_handler{*this};

//! Capnp list of pending promises.
boost::optional<kj::TaskSet> m_task_set;
std::unique_ptr<kj::TaskSet> m_task_set;

//! List of connections.
std::list<Connection> m_incoming_connections;
Expand Down
7 changes: 5 additions & 2 deletions src/mp/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,16 @@ void Connection::addAsyncCleanup(std::function<void()> 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()
Expand Down

0 comments on commit fb73b81

Please sign in to comment.