Skip to content

Commit d487f24

Browse files
committed
add doxygen
1 parent fe82394 commit d487f24

20 files changed

Lines changed: 2335 additions & 95 deletions

include/vix/async/core/cancel.hpp

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* @file cancel.hpp
44
* @author Gaspard Kirira
55
*
6-
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* Copyright 2025, Gaspard Kirira.
7+
* All rights reserved.
78
* https://github.com/vixcpp/vix
9+
*
810
* Use of this source code is governed by a MIT license
911
* that can be found in the License file.
1012
*
@@ -21,72 +23,163 @@
2123

2224
namespace vix::async::core
2325
{
26+
/**
27+
* @brief Shared cancellation state.
28+
*
29+
* cancel_state holds the atomic cancellation flag shared between
30+
* a cancel_source and all associated cancel_token instances.
31+
*
32+
* This object is reference-counted and designed to be safely
33+
* accessed concurrently from multiple threads.
34+
*/
2435
class cancel_state
2536
{
2637
public:
38+
/**
39+
* @brief Request cancellation.
40+
*
41+
* Sets the internal cancellation flag. This operation is
42+
* thread-safe and may be called multiple times.
43+
*/
2744
void request_cancel() noexcept
2845
{
2946
cancelled_.store(true, std::memory_order_release);
3047
}
3148

49+
/**
50+
* @brief Check whether cancellation was requested.
51+
*
52+
* @return true if cancellation has been requested, false otherwise.
53+
*/
3254
bool is_cancelled() const noexcept
3355
{
3456
return cancelled_.load(std::memory_order_acquire);
3557
}
3658

3759
private:
60+
/**
61+
* @brief Atomic cancellation flag.
62+
*/
3863
std::atomic<bool> cancelled_{false};
3964
};
4065

66+
/**
67+
* @brief Lightweight cancellation observer.
68+
*
69+
* cancel_token provides a read-only view of a cancellation state.
70+
* It does not own the state and cannot request cancellation itself.
71+
*
72+
* Tokens are cheap to copy and may be safely passed across threads.
73+
*/
4174
class cancel_token
4275
{
4376
public:
77+
/**
78+
* @brief Construct an empty (non-cancelable) token.
79+
*/
4480
cancel_token() = default;
4581

82+
/**
83+
* @brief Construct a token bound to a cancellation state.
84+
*
85+
* @param st Shared cancellation state.
86+
*/
4687
explicit cancel_token(std::shared_ptr<cancel_state> st) noexcept
4788
: st_(std::move(st)) {}
4889

49-
bool can_cancel() const noexcept { return static_cast<bool>(st_); }
90+
/**
91+
* @brief Check whether this token is associated with a cancel source.
92+
*
93+
* @return true if the token can observe cancellation, false otherwise.
94+
*/
95+
bool can_cancel() const noexcept
96+
{
97+
return static_cast<bool>(st_);
98+
}
5099

100+
/**
101+
* @brief Check whether cancellation has been requested.
102+
*
103+
* @return true if cancellation was requested, false otherwise.
104+
*/
51105
bool is_cancelled() const noexcept
52106
{
53107
return st_ ? st_->is_cancelled() : false;
54108
}
55109

56110
private:
111+
/**
112+
* @brief Shared cancellation state.
113+
*/
57114
std::shared_ptr<cancel_state> st_{};
58115
};
59116

117+
/**
118+
* @brief Cancellation source and owner.
119+
*
120+
* cancel_source owns the cancellation state and is responsible
121+
* for issuing cancellation requests. All tokens produced by
122+
* this source observe the same cancellation state.
123+
*/
60124
class cancel_source
61125
{
62126
public:
63-
cancel_source() : st_(std::make_shared<cancel_state>()) {}
64-
127+
/**
128+
* @brief Construct a new cancellation source.
129+
*
130+
* The associated cancellation state starts in a non-cancelled state.
131+
*/
132+
cancel_source()
133+
: st_(std::make_shared<cancel_state>()) {}
134+
135+
/**
136+
* @brief Obtain a cancellation token linked to this source.
137+
*
138+
* @return A cancel_token observing this source.
139+
*/
65140
cancel_token token() const noexcept
66141
{
67142
return cancel_token{st_};
68143
}
69144

145+
/**
146+
* @brief Request cancellation.
147+
*
148+
* Signals cancellation to all associated tokens.
149+
*/
70150
void request_cancel() noexcept
71151
{
72152
if (st_)
73153
st_->request_cancel();
74154
}
75155

156+
/**
157+
* @brief Check whether cancellation has been requested.
158+
*
159+
* @return true if cancellation was requested, false otherwise.
160+
*/
76161
bool is_cancelled() const noexcept
77162
{
78163
return st_ ? st_->is_cancelled() : false;
79164
}
80165

81166
private:
167+
/**
168+
* @brief Shared cancellation state.
169+
*/
82170
std::shared_ptr<cancel_state> st_;
83171
};
84172

173+
/**
174+
* @brief Standard error code for cancellation.
175+
*
176+
* @return std::error_code representing a cancelled operation.
177+
*/
85178
inline std::error_code cancelled_ec() noexcept
86179
{
87180
return make_error_code(errc::canceled);
88181
}
89182

90183
} // namespace vix::async::core
91184

92-
#endif
185+
#endif // VIX_ASYNC_CANCEL_HPP

include/vix/async/core/error.hpp

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* @file error.hpp
44
* @author Gaspard Kirira
55
*
6-
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* Copyright 2025, Gaspard Kirira.
7+
* All rights reserved.
78
* https://github.com/vixcpp/vix
9+
*
810
* Use of this source code is governed by a MIT license
911
* that can be found in the License file.
1012
*
@@ -21,37 +23,108 @@
2123
namespace vix::async::core
2224
{
2325

26+
/**
27+
* @brief Error codes for the async core subsystem.
28+
*
29+
* This enumeration defines all error conditions that can be
30+
* reported by the asynchronous runtime, scheduler, thread pool,
31+
* timers, and cancellation mechanisms.
32+
*
33+
* Values are intentionally compact and stable to allow efficient
34+
* propagation through std::error_code.
35+
*/
2436
enum class errc : std::uint8_t
2537
{
38+
/**
39+
* @brief No error.
40+
*/
2641
ok = 0,
2742

2843
// Generic
44+
45+
/**
46+
* @brief Invalid argument passed to an API.
47+
*/
2948
invalid_argument,
49+
50+
/**
51+
* @brief Operation cannot complete yet.
52+
*/
3053
not_ready,
54+
55+
/**
56+
* @brief Operation timed out.
57+
*/
3158
timeout,
59+
60+
/**
61+
* @brief Operation was canceled.
62+
*/
3263
canceled,
64+
65+
/**
66+
* @brief Resource or channel was closed.
67+
*/
3368
closed,
69+
70+
/**
71+
* @brief Capacity or numeric overflow.
72+
*/
3473
overflow,
3574

3675
// Scheduler / runtime
76+
77+
/**
78+
* @brief Runtime or scheduler has been stopped.
79+
*/
3780
stopped,
81+
82+
/**
83+
* @brief Internal task queue is full.
84+
*/
3885
queue_full,
3986

4087
// Thread pool
88+
89+
/**
90+
* @brief Task submission was rejected.
91+
*/
4192
rejected,
4293

4394
// Signals / timers
95+
96+
/**
97+
* @brief Operation is not supported on this platform.
98+
*/
4499
not_supported
45100
};
46101

102+
/**
103+
* @brief Error category for async core errors.
104+
*
105+
* Provides human-readable messages and categorization for
106+
* errc values. This category integrates with std::error_code
107+
* and std::error_condition.
108+
*/
47109
class error_category final : public std::error_category
48110
{
49111
public:
112+
/**
113+
* @brief Return the name of the error category.
114+
*
115+
* @return Category name ("async").
116+
*/
50117
const char *name() const noexcept override
51118
{
52119
return "async";
53120
}
54121

122+
/**
123+
* @brief Return a descriptive message for an error code.
124+
*
125+
* @param c Integer value of the error code.
126+
* @return Human-readable error message.
127+
*/
55128
std::string message(int c) const override
56129
{
57130
switch (static_cast<errc>(c))
@@ -84,25 +157,39 @@ namespace vix::async::core
84157
}
85158
};
86159

160+
/**
161+
* @brief Access the singleton async error category.
162+
*
163+
* @return Reference to the async error category.
164+
*/
87165
inline const std::error_category &category() noexcept
88166
{
89167
static error_category cat;
90168
return cat;
91169
}
92170

171+
/**
172+
* @brief Create a std::error_code from an async error code.
173+
*
174+
* @param e Async error code.
175+
* @return Corresponding std::error_code.
176+
*/
93177
inline std::error_code make_error_code(errc e) noexcept
94178
{
95179
return {static_cast<int>(e), category()};
96180
}
97181

98-
} // namespace async::core
182+
} // namespace vix::async::core
99183

100184
namespace std
101185
{
186+
/**
187+
* @brief Enable implicit conversion of errc to std::error_code.
188+
*/
102189
template <>
103190
struct is_error_code_enum<vix::async::core::errc> : true_type
104191
{
105192
};
106193
} // namespace std
107194

108-
#endif
195+
#endif // VIX_ASYNC_ERROR_HPP

0 commit comments

Comments
 (0)