Skip to content

Commit 950a900

Browse files
committed
Add auto-documentation comments for coro::facade, strategies for
coro::condition_variable_base
1 parent 731f182 commit 950a900

File tree

3 files changed

+91
-20
lines changed

3 files changed

+91
-20
lines changed

include/coro/condition_variable.hpp

+44-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ namespace coro
1616
namespace concepts
1717
{
1818
// clang-format off
19+
20+
21+
/**
22+
* Concept of basic capabilities condition_variable
23+
*/
1924
template<typename strategy_type>
2025
concept cv_strategy_base = requires(strategy_type s)
2126
{
@@ -24,6 +29,9 @@ concept cv_strategy_base = requires(strategy_type s)
2429
{ s.wait_for_notify() } -> coro::concepts::awaiter;
2530
};
2631

32+
/**
33+
* Concept of full capabilities condition_variable
34+
*/
2735
template<typename strategy_type>
2836
concept cv_strategy = cv_strategy_base<strategy_type> and requires(strategy_type s, coro::scoped_lock l, std::chrono::milliseconds d)
2937
{
@@ -35,12 +43,16 @@ concept cv_strategy = cv_strategy_base<strategy_type> and requires(strategy_type
3543
namespace detail
3644
{
3745

46+
/**
47+
* The strategy implementing basic features of condition_variable, such as wait(), notify_one(), notify_all(). Does not
48+
* require LIBCORO_FEATURE_NETWORKING for its operation
49+
*/
3850
class strategy_base
3951
{
4052
public:
4153
struct wait_operation
4254
{
43-
explicit wait_operation(strategy_base& cv);
55+
explicit wait_operation(strategy_base& strategy);
4456

4557
auto await_ready() const noexcept -> bool { return false; }
4658
auto await_suspend(std::coroutine_handle<> awaiting_coroutine) noexcept -> bool;
@@ -54,14 +66,18 @@ class strategy_base
5466
std::atomic<wait_operation*> m_next{nullptr};
5567
};
5668

69+
/**
70+
* Notifies and resumes one waiter immediately at the moment of the call, the calling coroutine will be forced to
71+
* wait for the switching of the awakened coroutine
72+
*/
5773
void notify_one() noexcept;
5874

5975
/**
6076
* Notifies and resume one awaiters onto the given executor. This will distribute
6177
* the waiters across the executor's threads.
6278
*/
6379
template<concepts::executor executor_type>
64-
[[nodiscard]] auto notify_one(executor_type& e) -> task<void>
80+
void notify_one(executor_type& e)
6581
{
6682
while (true)
6783
{
@@ -81,18 +97,20 @@ class strategy_base
8197
e.resume(current->m_awaiting_coroutine);
8298
break;
8399
}
84-
85-
co_return;
86100
}
87101

102+
/**
103+
* Notifies and resumes all awaiters immediately at the moment of the call, the calling coroutine will be forced to
104+
* wait for the switching of all awakened coroutines
105+
*/
88106
void notify_all() noexcept;
89107

90108
/**
91109
* Notifies and resumes all awaiters onto the given executor. This will distribute
92110
* the waiters across the executor's threads.
93111
*/
94112
template<concepts::executor executor_type>
95-
[[nodiscard]] auto notify_all(executor_type& e) -> task<void>
113+
void notify_all(executor_type& e)
96114
{
97115
while (true)
98116
{
@@ -132,8 +150,6 @@ class strategy_base
132150
e.resume(current->m_awaiting_coroutine);
133151
} while (next);
134152
}
135-
136-
co_return;
137153
}
138154

139155
/// Internal helper function to wait for a condition variable
@@ -150,6 +166,10 @@ class strategy_base
150166

151167
#ifdef LIBCORO_FEATURE_NETWORKING
152168

169+
/**
170+
* The strategy fully implements all the capabilities of condition_variable, including such as wait_for(), wait_until().
171+
* Requires LIBCORO_FEATURE_NETWORKING for its operation.
172+
*/
153173
class strategy_based_on_io_scheduler
154174
{
155175
public:
@@ -158,7 +178,7 @@ class strategy_based_on_io_scheduler
158178

159179
struct wait_operation
160180
{
161-
explicit wait_operation(strategy_based_on_io_scheduler& cv);
181+
explicit wait_operation(strategy_based_on_io_scheduler& strategy);
162182
~wait_operation();
163183

164184
auto await_ready() const noexcept -> bool { return false; }
@@ -234,18 +254,26 @@ class strategy_based_on_io_scheduler
234254
/// a task with a time limit
235255
[[nodiscard]] auto wait_task() -> task<bool>;
236256
};
257+
#endif
237258

238-
using default_strategy = strategy_based_on_io_scheduler;
259+
/**
260+
* You can set a custom default strategy for the coro::condition_variable
261+
*/
262+
#ifdef LIBCORO_CONDITION_VARIABLE_DEFAULT_STRATEGY
263+
using default_strategy = LIBCORO_CONDITION_VARIABLE_DEFAULT_STRATEGY;
239264
#else
265+
#ifdef LIBCORO_FEATURE_NETWORKING
266+
using default_strategy = strategy_based_on_io_scheduler;
267+
#else // LIBCORO_FEATURE_NETWORKING
240268
using default_strategy = strategy_base;
241-
#endif
242-
269+
#endif // LIBCORO_FEATURE_NETWORKING
270+
#endif // LIBCORO_CONDITION_VARIABLE_DEFAULT_STRATEGY
243271
} // namespace detail
244272

245273
/**
246-
* The coro::condition_variable is a thread safe async tool used with a coro::mutex (coro::scoped_lock)
274+
* The coro::condition_variable_base is a thread safe async tool used with a coro::mutex (coro::scoped_lock)
247275
* to suspend one or more coro::task until another coro::task both modifies a shared variable
248-
* (the condition) and notifies the coro::condition_variable
276+
* (the condition) and notifies the coro::condition_variable_base
249277
*/
250278
template<concepts::cv_strategy_base Strategy>
251279
class condition_variable_base : public Strategy
@@ -434,6 +462,9 @@ inline auto condition_variable_base<Strategy>::wait_for(
434462
}
435463
}
436464

465+
/**
466+
* this is coro::condition_variable_base with default strategy parameter (coro::detail::default_strategy)
467+
*/
437468
using condition_variable = condition_variable_base<detail::default_strategy>;
438469

439470
} // namespace coro

include/coro/facade.hpp

+44-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
namespace coro
1010
{
1111

12+
/**
13+
* Facade for universal access to default scheduler or default thread pool.
14+
* This facade supports the concept of coro::concepts::executor.
15+
*/
1216
class facade
1317
{
1418
public:
1519
facade();
20+
21+
/**
22+
* Getting a single instance of facade per process
23+
* @return single instance of facade
24+
*/
1625
static facade* instance();
1726

1827
#ifdef LIBCORO_FEATURE_NETWORKING
@@ -44,19 +53,50 @@ class facade
4453
}
4554

4655
#ifdef LIBCORO_FEATURE_NETWORKING
47-
static void set_io_scheduler_options(io_scheduler::options io_scheduler_options);
56+
/**
57+
* Set up default coro::io_scheduler::options before constructing a single instance of the facade
58+
* @param io_scheduler_options io_scheduler options
59+
*/
60+
static void set_io_scheduler_options(io_scheduler::options io_scheduler_options);
61+
62+
/**
63+
* Get default coro::io_scheduler
64+
*/
4865
std::shared_ptr<io_scheduler> get_io_scheduler();
4966
#else
50-
static void set_thread_pool_options(thread_pool::options thread_pool_options);
67+
/**
68+
* Set up default coro::thread_pool::options before constructing a single instance of the facade
69+
* @param thread_pool_options thread_pool options
70+
*/
71+
static void set_thread_pool_options(thread_pool::options thread_pool_options);
72+
73+
/**
74+
* Get default coro::thread_pool
75+
*/
5176
std::shared_ptr<thread_pool> get_thread_pool();
5277
#endif
5378

5479
private:
5580
#ifdef LIBCORO_FEATURE_NETWORKING
56-
static io_scheduler::options s_io_scheduler_options;
81+
/**
82+
* Options for default coro::io_scheduler
83+
*/
84+
static io_scheduler::options s_io_scheduler_options;
85+
86+
/**
87+
* Default coro::io_scheduler
88+
*/
5789
std::shared_ptr<io_scheduler> m_io_scheduler;
5890
#else
59-
static thread_pool::options s_thread_pool_options;
91+
92+
/**
93+
* Options for default coro::thread_pool
94+
*/
95+
static thread_pool::options s_thread_pool_options;
96+
97+
/**
98+
* Default coro::thread_pool
99+
*/
60100
std::shared_ptr<thread_pool> m_thread_pool;
61101
#endif
62102
};

src/condition_variable.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ detail::strategy_based_on_io_scheduler::wait_operation_guard detail::strategy_ba
211211
return result;
212212
}
213213

214-
detail::strategy_based_on_io_scheduler::wait_operation::wait_operation(detail::strategy_based_on_io_scheduler& cv)
215-
: m_strategy(cv)
214+
detail::strategy_based_on_io_scheduler::wait_operation::wait_operation(detail::strategy_based_on_io_scheduler& strategy)
215+
: m_strategy(strategy)
216216
{
217217
}
218218

@@ -263,7 +263,7 @@ detail::strategy_based_on_io_scheduler::wait_operation*
263263

264264
#endif
265265

266-
detail::strategy_base::wait_operation::wait_operation(detail::strategy_base& cv) : m_strategy(cv)
266+
detail::strategy_base::wait_operation::wait_operation(detail::strategy_base& strategy) : m_strategy(strategy)
267267
{
268268
}
269269

0 commit comments

Comments
 (0)