Condy v1.5.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_ || enable_coop_taskrun_) {
95 throw std::logic_error(
96 "sqpoll cannot be enabled with defer_taskrun or coop_taskrun");
97 }
98 enable_sqpoll_ = true;
99 sqpoll_idle_time_ms_ = idle_time_ms;
100 sqpoll_thread_cpu_ = cpu;
101 return *this;
102 }
103
109 if (enable_sqpoll_ || enable_coop_taskrun_) {
110 throw std::logic_error(
111 "defer_taskrun cannot be enabled with sqpoll or coop_taskrun");
112 }
113 enable_defer_taskrun_ = true;
114 return *this;
115 }
116
121 Self &sq_size(size_t v) {
122 sq_size_ = v;
123 return *this;
124 }
125
130 Self &cq_size(size_t v) {
131 cq_size_ = v;
132 return *this;
133 }
134
141 Self &enable_attach_wq(Runtime &other) {
142 attach_wq_target_ = &other;
143 return *this;
144 }
145
151 if (enable_sqpoll_ || enable_defer_taskrun_) {
152 throw std::logic_error(
153 "coop_taskrun cannot be enabled with sqpoll or defer_taskrun");
154 }
155 enable_coop_taskrun_ = true;
156 return *this;
157 }
158
165 [[deprecated("Use enable_coop_taskrun() without parameters instead")]]
166 Self &enable_coop_taskrun([[maybe_unused]] bool taskrun_flag) {
168 return *this;
169 }
170
175 if (enable_sqe_mixed_) {
176 throw std::logic_error("sqe128 cannot be enabled with sqe_mixed");
177 }
178 enable_sqe128_ = true;
179 return *this;
180 }
181
185 Self &enable_cqe32() {
186 if (enable_cqe_mixed_) {
187 throw std::logic_error("cqe32 cannot be enabled with cqe_mixed");
188 }
189 enable_cqe32_ = true;
190 return *this;
191 }
192
193#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
198 if (enable_sqe128_) {
199 throw std::logic_error("sqe_mixed cannot be enabled with sqe128");
200 }
201 enable_sqe_mixed_ = true;
202 return *this;
203 }
204#endif
205
206#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
211 if (enable_cqe32_) {
212 throw std::logic_error("cqe_mixed cannot be enabled with cqe32");
213 }
214 enable_cqe_mixed_ = true;
215 return *this;
216 }
217#endif
218
219#if !IO_URING_CHECK_VERSION(2, 5) // >= 2.5
225 Self &enable_no_mmap(void *buf = nullptr, size_t buf_size = 0) {
226 enable_no_mmap_ = true;
227 no_mmap_buf_ = buf;
228 no_mmap_buf_size_ = buf_size;
229 return *this;
230 }
231#endif
232
233protected:
234 size_t event_interval_ = 61;
235 bool disable_register_ring_fd_ = false;
236 bool enable_iopoll_ = false;
237 bool enable_hybrid_iopoll_ = false;
238 bool enable_sqpoll_ = false;
239 size_t sqpoll_idle_time_ms_ = 1000;
240 std::optional<uint32_t> sqpoll_thread_cpu_ = std::nullopt;
241 bool enable_defer_taskrun_ = false;
242 size_t sq_size_ = 128;
243 size_t cq_size_ = 0; // 0 means default
244 Runtime *attach_wq_target_ = nullptr;
245 bool enable_coop_taskrun_ = false;
246 bool enable_sqe128_ = false;
247 bool enable_cqe32_ = false;
248 bool enable_sqe_mixed_ = false;
249 bool enable_cqe_mixed_ = false;
250 bool enable_no_mmap_ = false;
251 void *no_mmap_buf_ = nullptr;
252 size_t no_mmap_buf_size_ = 0;
253
254 friend class Runtime;
255};
256
257} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:68
The main namespace for the Condy library.
Definition condy.hpp:28
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.