Skip to content

Commit 0870b05

Browse files
committed
Add Javadoc documentation to all public headers
Review and document every public class, struct, enum, function, type alias, and data member across 18 headers. Follows the project Javadoc conventions: /// for trivial briefs, /** */ for non-trivial, proper verb starts (Return, Construct, Check, etc.), and @see/@param where appropriate. Closes #121
1 parent 32dfdbb commit 0870b05

18 files changed

+401
-65
lines changed

include/boost/corosio/detail/except.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,33 @@
1515

1616
namespace boost::corosio::detail {
1717

18+
/// Throw `std::logic_error` with a default message.
1819
[[noreturn]] BOOST_COROSIO_DECL void throw_logic_error();
20+
21+
/** Throw `std::logic_error` with the given message.
22+
23+
@param what Null-terminated message string.
24+
25+
@throws std::logic_error Always.
26+
*/
1927
[[noreturn]] BOOST_COROSIO_DECL void throw_logic_error(char const* what);
2028

29+
/** Throw `std::system_error` from @p ec.
30+
31+
@param ec Error code used to construct the exception.
32+
33+
@throws std::system_error Always.
34+
*/
2135
[[noreturn]] BOOST_COROSIO_DECL void
2236
throw_system_error(std::error_code const& ec);
2337

38+
/** Throw `std::system_error` from @p ec with the given context.
39+
40+
@param ec Error code used to construct the exception.
41+
@param what Null-terminated context string.
42+
43+
@throws std::system_error Always.
44+
*/
2445
[[noreturn]] BOOST_COROSIO_DECL void
2546
throw_system_error(std::error_code const& ec, char const* what);
2647

include/boost/corosio/detail/scheduler.hpp

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,61 @@ namespace boost::corosio::detail {
2020

2121
class scheduler_op;
2222

23+
/** Define the abstract interface for the event loop scheduler.
24+
25+
Concrete backends (epoll, IOCP, kqueue, select) derive from
26+
this to implement the reactor/proactor event loop. The
27+
@ref io_context delegates all scheduling operations here.
28+
29+
@see io_context, native_scheduler
30+
*/
2331
struct BOOST_COROSIO_DECL scheduler
2432
{
25-
virtual ~scheduler() = default;
33+
virtual ~scheduler() = default;
34+
35+
/// Post a coroutine handle for deferred execution.
2636
virtual void post(std::coroutine_handle<>) const = 0;
27-
virtual void post(scheduler_op*) const = 0;
2837

29-
virtual void work_started() noexcept = 0;
38+
/// Post a scheduler operation for deferred execution.
39+
virtual void post(scheduler_op*) const = 0;
40+
41+
/// Increment the outstanding work count.
42+
virtual void work_started() noexcept = 0;
43+
44+
/// Decrement the outstanding work count.
3045
virtual void work_finished() noexcept = 0;
3146

47+
/// Check if the calling thread is running the event loop.
3248
virtual bool running_in_this_thread() const noexcept = 0;
33-
virtual void stop() = 0;
34-
virtual bool stopped() const noexcept = 0;
35-
virtual void restart() = 0;
36-
virtual std::size_t run() = 0;
37-
virtual std::size_t run_one() = 0;
38-
virtual std::size_t wait_one(long usec) = 0;
39-
virtual std::size_t poll() = 0;
40-
virtual std::size_t poll_one() = 0;
49+
50+
/// Signal the event loop to stop.
51+
virtual void stop() = 0;
52+
53+
/// Check if the event loop has been stopped.
54+
virtual bool stopped() const noexcept = 0;
55+
56+
/// Reset the stopped state so `run()` can be called again.
57+
virtual void restart() = 0;
58+
59+
/// Run the event loop, blocking until all work completes.
60+
virtual std::size_t run() = 0;
61+
62+
/// Run one handler, blocking until one completes.
63+
virtual std::size_t run_one() = 0;
64+
65+
/** Run one handler, blocking up to @p usec microseconds.
66+
67+
@param usec Maximum wait time in microseconds.
68+
69+
@return The number of handlers executed (0 or 1).
70+
*/
71+
virtual std::size_t wait_one(long usec) = 0;
72+
73+
/// Run all ready handlers without blocking.
74+
virtual std::size_t poll() = 0;
75+
76+
/// Run at most one ready handler without blocking.
77+
virtual std::size_t poll_one() = 0;
4178
};
4279

4380
} // namespace boost::corosio::detail

include/boost/corosio/detail/timer_service.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,26 @@ class BOOST_COROSIO_DECL timer_service final
8686
using clock_type = std::chrono::steady_clock;
8787
using time_point = clock_type::time_point;
8888

89+
/// Type-erased callback for earliest-expiry-changed notifications.
8990
class callback
9091
{
9192
void* ctx_ = nullptr;
9293
void (*fn_)(void*) = nullptr;
9394

9495
public:
96+
/// Construct an empty callback.
9597
callback() = default;
98+
99+
/// Construct a callback with the given context and function.
96100
callback(void* ctx, void (*fn)(void*)) noexcept : ctx_(ctx), fn_(fn) {}
97101

102+
/// Return true if the callback is non-empty.
98103
explicit operator bool() const noexcept
99104
{
100105
return fn_ != nullptr;
101106
}
107+
108+
/// Invoke the callback.
102109
void operator()() const
103110
{
104111
if (fn_)
@@ -126,49 +133,78 @@ class BOOST_COROSIO_DECL timer_service final
126133
(std::numeric_limits<std::int64_t>::max)()};
127134

128135
public:
136+
/// Construct the timer service bound to a scheduler.
129137
inline timer_service(capy::execution_context&, scheduler& sched)
130138
: sched_(&sched)
131139
{
132140
}
133141

142+
/// Return the associated scheduler.
134143
inline scheduler& get_scheduler() noexcept
135144
{
136145
return *sched_;
137146
}
138147

148+
/// Destroy the timer service.
139149
~timer_service() override = default;
140150

141151
timer_service(timer_service const&) = delete;
142152
timer_service& operator=(timer_service const&) = delete;
143153

154+
/// Register a callback invoked when the earliest expiry changes.
144155
inline void set_on_earliest_changed(callback cb)
145156
{
146157
on_earliest_changed_ = cb;
147158
}
148159

160+
/// Return true if no timers are in the heap.
149161
inline bool empty() const noexcept
150162
{
151163
return cached_nearest_ns_.load(std::memory_order_acquire) ==
152164
(std::numeric_limits<std::int64_t>::max)();
153165
}
154166

167+
/// Return the nearest timer expiry without acquiring the mutex.
155168
inline time_point nearest_expiry() const noexcept
156169
{
157170
auto ns = cached_nearest_ns_.load(std::memory_order_acquire);
158171
return time_point(time_point::duration(ns));
159172
}
160173

174+
/// Cancel all pending timers and free cached resources.
161175
inline void shutdown() override;
176+
177+
/// Construct a new timer implementation.
162178
inline io_object::implementation* construct() override;
179+
180+
/// Destroy a timer implementation, cancelling pending waiters.
163181
inline void destroy(io_object::implementation* p) override;
182+
183+
/// Cancel and recycle a timer implementation.
164184
inline void destroy_impl(implementation& impl);
185+
186+
/// Create or recycle a waiter node.
165187
inline waiter_node* create_waiter();
188+
189+
/// Return a waiter node to the cache or free list.
166190
inline void destroy_waiter(waiter_node* w);
191+
192+
/// Update the timer expiry, cancelling existing waiters.
167193
inline std::size_t update_timer(implementation& impl, time_point new_time);
194+
195+
/// Insert a waiter into the timer's waiter list and the heap.
168196
inline void insert_waiter(implementation& impl, waiter_node* w);
197+
198+
/// Cancel all waiters on a timer.
169199
inline std::size_t cancel_timer(implementation& impl);
200+
201+
/// Cancel a single waiter ( stop_token callback path ).
170202
inline void cancel_waiter(waiter_node* w);
203+
204+
/// Cancel one waiter on a timer.
171205
inline std::size_t cancel_one_waiter(implementation& impl);
206+
207+
/// Complete all waiters whose timers have expired.
172208
inline std::size_t process_expired();
173209

174210
private:

include/boost/corosio/io/io_object.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class BOOST_COROSIO_DECL io_object
223223
io_object(io_object const&) = delete;
224224
io_object& operator=(io_object const&) = delete;
225225

226+
/// The platform I/O handle owned by this object.
226227
handle h_;
227228
};
228229

include/boost/corosio/io/io_signal_set.hpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,35 @@ class BOOST_COROSIO_DECL io_signal_set : public io_object
6868
};
6969

7070
public:
71+
/** Define backend hooks for signal set wait and cancel.
72+
73+
Platform backends derive from this to implement
74+
signal delivery notification.
75+
*/
7176
struct implementation : io_object::implementation
7277
{
78+
/** Initiate an asynchronous wait for a signal.
79+
80+
@param h Coroutine handle to resume on completion.
81+
@param ex Executor for dispatching the completion.
82+
@param token Stop token for cancellation.
83+
@param ec Output error code.
84+
@param signo Output signal number.
85+
86+
@return Coroutine handle to resume immediately.
87+
*/
7388
virtual std::coroutine_handle<> wait(
74-
std::coroutine_handle<>,
75-
capy::executor_ref,
76-
std::stop_token,
77-
std::error_code*,
78-
int*) = 0;
89+
std::coroutine_handle<> h,
90+
capy::executor_ref ex,
91+
std::stop_token token,
92+
std::error_code* ec,
93+
int* signo) = 0;
94+
95+
/** Cancel all pending wait operations.
7996
97+
Cancelled waiters complete with an error that
98+
compares equal to `capy::cond::canceled`.
99+
*/
80100
virtual void cancel() = 0;
81101
};
82102

include/boost/corosio/io/io_timer.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,28 @@ class BOOST_COROSIO_DECL io_timer : public io_object
8383
};
8484

8585
public:
86+
/** Backend interface for timer wait operations.
87+
88+
Holds per-timer state (expiry, heap position) and provides
89+
the virtual `wait` entry point that concrete timer services
90+
override.
91+
*/
8692
struct implementation : io_object::implementation
8793
{
94+
/// Sentinel value indicating the timer is not in the heap.
8895
static constexpr std::size_t npos =
8996
(std::numeric_limits<std::size_t>::max)();
9097

98+
/// The absolute expiry time point.
9199
std::chrono::steady_clock::time_point expiry_{};
92-
std::size_t heap_index_ = npos;
100+
101+
/// Index in the timer service's min-heap, or `npos`.
102+
std::size_t heap_index_ = npos;
103+
104+
/// True if `wait()` has been called since last cancel.
93105
bool might_have_pending_waits_ = false;
94106

107+
/// Initiate an asynchronous wait for the timer to expire.
95108
virtual std::coroutine_handle<> wait(
96109
std::coroutine_handle<>,
97110
capy::executor_ref,

include/boost/corosio/native/native.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
// Official repository: https://github.com/cppalliance/corosio
88
//
99

10+
/** @file native.hpp
11+
12+
Include all native (devirtualized) public headers:
13+
I/O context, sockets, acceptor, resolver, signal set,
14+
timer, and cancellation helpers.
15+
*/
16+
1017
#ifndef BOOST_COROSIO_NATIVE_NATIVE_HPP
1118
#define BOOST_COROSIO_NATIVE_NATIVE_HPP
1219

include/boost/corosio/native/native_scheduler.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ namespace boost::corosio::detail {
1616

1717
class timer_service;
1818

19-
// Intermediary between public scheduler and concrete backends,
20-
// holds cached service pointers behind the compilation firewall
19+
/** Cache service pointers for native backend schedulers.
20+
21+
Sits between @ref scheduler and the concrete backend schedulers,
22+
storing service pointers that would otherwise require a virtual
23+
call or service lookup on every timer operation.
24+
25+
@see scheduler
26+
*/
2127
struct native_scheduler : scheduler
2228
{
29+
/// Store the timer service pointer, set during construction.
2330
timer_service* timer_svc_ = nullptr;
2431
};
2532

0 commit comments

Comments
 (0)