![]() |
Bitcoin Core 29.99.0
P2P Digital Currency
|
Event loop implementation. More...
#include <proxy-io.h>
Public Member Functions | |
EventLoop (const char *exe_name, LogFn log_fn, void *context=nullptr) | |
Construct event loop object. More... | |
~EventLoop () | |
void | loop () |
Run event loop. More... | |
void | post (const std::function< void()> &fn) |
Run function on event loop thread. More... | |
template<typename Callable > | |
void | sync (Callable &&callable) |
Wrapper around EventLoop::post that takes advantage of the fact that callable will not go out of scope to avoid requirement that it be copyable. More... | |
void | startAsyncThread (std::unique_lock< std::mutex > &lock) |
Start asynchronous worker thread if necessary. More... | |
void | addClient (std::unique_lock< std::mutex > &lock) |
Add/remove remote client reference counts. More... | |
bool | removeClient (std::unique_lock< std::mutex > &lock) |
bool | done (std::unique_lock< std::mutex > &lock) |
Check if loop should exit. More... | |
Logger | log () |
Logger | logPlain () |
Logger | raise () |
Public Attributes | |
const char * | m_exe_name |
Process name included in thread names so combined debug output from multiple processes is easier to understand. More... | |
std::thread::id | m_thread_id = std::this_thread::get_id() |
ID of the event loop thread. More... | |
std::thread | m_async_thread |
Handle of an async worker thread. More... | |
const std::function< void()> * | m_post_fn = nullptr |
Callback function to run on event loop thread during post() or sync() call. More... | |
CleanupList | m_async_fns |
Callback functions to run on async thread. More... | |
int | m_wait_fd = -1 |
Pipe read handle used to wake up the event loop thread. More... | |
int | m_post_fd = -1 |
Pipe write handle used to wake up the event loop thread. More... | |
int | m_num_clients = 0 |
Number of clients holding references to ProxyServerBase objects that reference this event loop. More... | |
std::mutex | m_mutex |
Mutex and condition variable used to post tasks to event loop and async thread. More... | |
std::condition_variable | m_cv |
kj::AsyncIoContext | m_io_context |
Capnp IO context. More... | |
LoggingErrorHandler | m_error_handler {*this} |
Capnp error handler. Needs to outlive m_task_set. More... | |
std::unique_ptr< kj::TaskSet > | m_task_set |
Capnp list of pending promises. More... | |
std::list< Connection > | m_incoming_connections |
List of connections. More... | |
LogFn | m_log_fn |
External logging callback. More... | |
void * | m_context |
External context pointer. More... | |
Event loop implementation.
Based on https://groups.google.com/d/msg/capnproto/TuQFF1eH2-M/g81sHaTAAQAJ
Definition at line 133 of file proxy-io.h.
mp::EventLoop::EventLoop | ( | const char * | exe_name, |
LogFn | log_fn, | ||
void * | context = nullptr |
||
) |
void mp::EventLoop::addClient | ( | std::unique_lock< std::mutex > & | lock | ) |
bool mp::EventLoop::done | ( | std::unique_lock< std::mutex > & | lock | ) |
|
inline |
Definition at line 177 of file proxy-io.h.
|
inline |
Definition at line 183 of file proxy-io.h.
void mp::EventLoop::loop | ( | ) |
void mp::EventLoop::post | ( | const std::function< void()> & | fn | ) |
|
inline |
Definition at line 184 of file proxy-io.h.
bool mp::EventLoop::removeClient | ( | std::unique_lock< std::mutex > & | lock | ) |
void mp::EventLoop::startAsyncThread | ( | std::unique_lock< std::mutex > & | lock | ) |
Start asynchronous worker thread if necessary.
This is only done if there are ProxyServerBase::m_impl objects that need to be destroyed asynchronously, without tying up the event loop thread. This can happen when an interface does not declare a destroy() method that would allow the client to wait for the destructor to finish and run it on a dedicated thread. It can also happen whenever this is a broken connection and the client is no longer around to call the destructors and the server objects need to be garbage collected. In both cases, it is important that ProxyServer::m_impl destructors do not run on the eventloop thread because they may need it to do I/O if they perform other IPC calls.
Definition at line 256 of file proxy.cpp.
|
inline |
Wrapper around EventLoop::post that takes advantage of the fact that callable will not go out of scope to avoid requirement that it be copyable.
Definition at line 153 of file proxy-io.h.
CleanupList mp::EventLoop::m_async_fns |
Callback functions to run on async thread.
Definition at line 201 of file proxy-io.h.
std::thread mp::EventLoop::m_async_thread |
Handle of an async worker thread.
Joined on destruction. Unset if async method has not been called.
Definition at line 195 of file proxy-io.h.
void* mp::EventLoop::m_context |
External context pointer.
Definition at line 234 of file proxy-io.h.
std::condition_variable mp::EventLoop::m_cv |
Definition at line 216 of file proxy-io.h.
LoggingErrorHandler mp::EventLoop::m_error_handler {*this} |
Capnp error handler. Needs to outlive m_task_set.
Definition at line 222 of file proxy-io.h.
const char* mp::EventLoop::m_exe_name |
Process name included in thread names so combined debug output from multiple processes is easier to understand.
Definition at line 188 of file proxy-io.h.
std::list<Connection> mp::EventLoop::m_incoming_connections |
List of connections.
Definition at line 228 of file proxy-io.h.
kj::AsyncIoContext mp::EventLoop::m_io_context |
Capnp IO context.
Definition at line 219 of file proxy-io.h.
LogFn mp::EventLoop::m_log_fn |
External logging callback.
Definition at line 231 of file proxy-io.h.
std::mutex mp::EventLoop::m_mutex |
Mutex and condition variable used to post tasks to event loop and async thread.
Definition at line 215 of file proxy-io.h.
int mp::EventLoop::m_num_clients = 0 |
Number of clients holding references to ProxyServerBase objects that reference this event loop.
Definition at line 211 of file proxy-io.h.
int mp::EventLoop::m_post_fd = -1 |
Pipe write handle used to wake up the event loop thread.
Definition at line 207 of file proxy-io.h.
const std::function<void()>* mp::EventLoop::m_post_fn = nullptr |
Callback function to run on event loop thread during post() or sync() call.
Definition at line 198 of file proxy-io.h.
std::unique_ptr<kj::TaskSet> mp::EventLoop::m_task_set |
Capnp list of pending promises.
Definition at line 225 of file proxy-io.h.
std::thread::id mp::EventLoop::m_thread_id = std::this_thread::get_id() |
ID of the event loop thread.
Definition at line 191 of file proxy-io.h.
int mp::EventLoop::m_wait_fd = -1 |
Pipe read handle used to wake up the event loop thread.
Definition at line 204 of file proxy-io.h.