Condy v1.6.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
runtime_options.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
8#include <cstddef>
9#include <cstdint>
10#include <optional>
11#include <stdexcept>
12
13namespace condy {
14
15class Runtime;
16
24public:
25 using Self = RuntimeOptions;
26
33 Self &event_interval(size_t v) {
34 event_interval_ = v;
35 return *this;
36 }
37
45 disable_register_ring_fd_ = true;
46 return *this;
47 }
48
54 [[deprecated("Use enable_iopoll() and enable_hybrid_iopoll() instead")]]
55 Self &enable_iopoll([[maybe_unused]] bool hybrid) {
57#if !IO_URING_CHECK_VERSION(2, 9) // >= 2.9
58 if (hybrid) {
60 }
61#endif
62 return *this;
63 }
64
68 Self &enable_iopoll() {
69 enable_iopoll_ = true;
70 return *this;
71 }
72
73#if !IO_URING_CHECK_VERSION(2, 9) // >= 2.9
78 if (!enable_iopoll_) {
79 throw std::logic_error(
80 "hybrid_iopoll cannot be enabled without iopoll");
81 }
82 enable_hybrid_iopoll_ = true;
83 return *this;
84 }
85#endif
86
92 Self &enable_sqpoll(size_t idle_time_ms = 1000,
93 std::optional<uint32_t> cpu = std::nullopt) {
94 if (enable_defer_taskrun_) {
95 throw std::logic_error(
96 "sqpoll cannot be enabled with defer_taskrun");
97 }
98 if (enable_coop_taskrun_) {
99 throw std::logic_error(
100 "sqpoll cannot be enabled with coop_taskrun");
101 }
102 if (enable_sq_rewind_) {
103 throw std::logic_error("sqpoll cannot be enabled with sq_rewind");
104 }
105 enable_sqpoll_ = true;
106 sqpoll_idle_time_ms_ = idle_time_ms;
107 sqpoll_thread_cpu_ = cpu;
108 return *this;
109 }
110
116 if (enable_sqpoll_) {
117 throw std::logic_error(
118 "defer_taskrun cannot be enabled with sqpoll");
119 }
120 if (enable_coop_taskrun_) {
121 throw std::logic_error(
122 "defer_taskrun cannot be enabled with coop_taskrun");
123 }
124 enable_defer_taskrun_ = true;
125 return *this;
126 }
127
132 Self &sq_size(size_t v) {
133 sq_size_ = v;
134 return *this;
135 }
136
141 Self &cq_size(size_t v) {
142 cq_size_ = v;
143 return *this;
144 }
145
152 Self &enable_attach_wq(Runtime &other) {
153 attach_wq_target_ = &other;
154 return *this;
155 }
156
162 if (enable_sqpoll_) {
163 throw std::logic_error(
164 "coop_taskrun cannot be enabled with sqpoll");
165 }
166 if (enable_defer_taskrun_) {
167 throw std::logic_error(
168 "coop_taskrun cannot be enabled with defer_taskrun");
169 }
170 enable_coop_taskrun_ = true;
171 return *this;
172 }
173
180 [[deprecated("Use enable_coop_taskrun() without parameters instead")]]
181 Self &enable_coop_taskrun([[maybe_unused]] bool taskrun_flag) {
183 return *this;
184 }
185
190 if (enable_sqe_mixed_) {
191 throw std::logic_error("sqe128 cannot be enabled with sqe_mixed");
192 }
193 enable_sqe128_ = true;
194 return *this;
195 }
196
200 Self &enable_cqe32() {
201 if (enable_cqe_mixed_) {
202 throw std::logic_error("cqe32 cannot be enabled with cqe_mixed");
203 }
204 enable_cqe32_ = true;
205 return *this;
206 }
207
208#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
213 if (enable_sqe128_) {
214 throw std::logic_error("sqe_mixed cannot be enabled with sqe128");
215 }
216 enable_sqe_mixed_ = true;
217 return *this;
218 }
219#endif
220
221#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
226 if (enable_cqe32_) {
227 throw std::logic_error("cqe_mixed cannot be enabled with cqe32");
228 }
229 enable_cqe_mixed_ = true;
230 return *this;
231 }
232#endif
233
234#if !IO_URING_CHECK_VERSION(2, 5) // >= 2.5
240 Self &enable_no_mmap(void *buf = nullptr, size_t buf_size = 0) {
241 enable_no_mmap_ = true;
242 no_mmap_buf_ = buf;
243 no_mmap_buf_size_ = buf_size;
244 return *this;
245 }
246#endif
247
248#if !IO_URING_CHECK_VERSION(2, 14) // >= 2.14
253 if (enable_sqpoll_) {
254 throw std::logic_error("sq_rewind cannot be enabled with sqpoll");
255 }
256 enable_sq_rewind_ = true;
257 return *this;
258 }
259#endif
260
261protected:
262 size_t event_interval_ = 61;
263 bool disable_register_ring_fd_ = false;
264 bool enable_iopoll_ = false;
265 bool enable_hybrid_iopoll_ = false;
266 bool enable_sqpoll_ = false;
267 size_t sqpoll_idle_time_ms_ = 1000;
268 std::optional<uint32_t> sqpoll_thread_cpu_ = std::nullopt;
269 bool enable_defer_taskrun_ = false;
270 size_t sq_size_ = 128;
271 size_t cq_size_ = 0; // 0 means default
272 Runtime *attach_wq_target_ = nullptr;
273 bool enable_coop_taskrun_ = false;
274 bool enable_sqe128_ = false;
275 bool enable_cqe32_ = false;
276 bool enable_sqe_mixed_ = false;
277 bool enable_cqe_mixed_ = false;
278 bool enable_no_mmap_ = false;
279 void *no_mmap_buf_ = nullptr;
280 size_t no_mmap_buf_size_ = 0;
281 bool enable_sq_rewind_ = false;
282
283 friend class Runtime;
284};
285
286} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:111
The main namespace for the Condy library.
Definition condy.hpp:30
Self & enable_coop_taskrun(bool taskrun_flag)
See IORING_SETUP_COOP_TASKRUN.
Self & enable_iopoll(bool hybrid)
See IORING_SETUP_IOPOLL.
Self & enable_sqe128()
See IORING_SETUP_SQE128.
Self & enable_attach_wq(Runtime &other)
See IORING_SETUP_ATTACH_WQ.
Self & enable_iopoll()
See IORING_SETUP_IOPOLL.
Self & sq_size(size_t v)
Set SQ size.
Self & enable_no_mmap(void *buf=nullptr, size_t buf_size=0)
See IORING_SETUP_NO_MMAP.
Self & cq_size(size_t v)
Set CQ size.
Self & enable_hybrid_iopoll()
See IORING_SETUP_HYBRID_IOPOLL.
Self & disable_register_ring_fd()
Disable register ring fd.
Self & enable_coop_taskrun()
See IORING_SETUP_COOP_TASKRUN and IORING_SETUP_TASKRUN_FLAG.
Self & enable_cqe32()
See IORING_SETUP_CQE32.
Self & event_interval(size_t v)
Set event interval.
Self & enable_cqe_mixed()
See IORING_SETUP_CQE_MIXED.
Self & enable_sqpoll(size_t idle_time_ms=1000, std::optional< uint32_t > cpu=std::nullopt)
See IORING_SETUP_SQPOLL.
Self & enable_sqe_mixed()
See IORING_SETUP_SQE_MIXED.
Self & enable_defer_taskrun()
See IORING_SETUP_DEFER_TASKRUN and IORING_SETUP_TASKRUN_FLAG.
Self & enable_sq_rewind()
See IORING_SETUP_SQ_REWIND.