Skip to content

Commit f58c8d8

Browse files
committed
proxy-io.h: Add more detailed EventLoop comment
1 parent 5108445 commit f58c8d8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/mp/proxy-io.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ std::string LongThreadName(const char* exe_name);
129129

130130
//! Event loop implementation.
131131
//!
132+
//! Cap'n Proto threading model is very simple: all I/O operations are
133+
//! asynchronous and must be performed on a single thread. This includes:
134+
//!
135+
//! - Code starting an asynchronous operation (calling a function that returns a
136+
//! promise object)
137+
//! - Code notifying that an asynchronous operation is complete (code using a
138+
//! fulfiller object)
139+
//! - Code handling a completed operation (code chaining or waiting for a promise)
140+
//!
141+
//! All of this code needs to access shared state, and there is no mutex that
142+
//! can be acquired to lock this state because Cap'n Proto
143+
//! assumes it will only be accessed from one thread. So all this code needs to
144+
//! actually run on one thread, and the EventLoop::loop() method is the entry point for
145+
//! this thread. ProxyClient and ProxyServer objects that use other threads and
146+
//! need to perform I/O operations post to this thread using EventLoop::post()
147+
//! and EventLoop::sync() methods.
148+
//!
149+
//! Specifically, because ProxyClient methods can be called from arbitrary
150+
//! threads, and ProxyServer methods can run on arbitrary threads, ProxyClient
151+
//! methods use the EventLoop thread to send requests, and ProxyServer methods
152+
//! use the thread to return results.
153+
//!
132154
//! Based on https://groups.google.com/d/msg/capnproto/TuQFF1eH2-M/g81sHaTAAQAJ
133155
class EventLoop
134156
{

0 commit comments

Comments
 (0)