Condy v1.3.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
53 Self &enable_iopoll(bool hybrid = false) {
54 enable_iopoll_ = true;
55 enable_hybrid_iopoll_ = hybrid;
56 return *this;
57 }
58
64 Self &enable_sqpoll(size_t idle_time_ms = 1000,
65 std::optional<uint32_t> cpu = std::nullopt) {
66 if (enable_defer_taskrun_ || enable_coop_taskrun_) {
67 throw std::logic_error(
68 "sqpoll cannot be enabled with defer_taskrun or coop_taskrun");
69 }
70 enable_sqpoll_ = true;
71 sqpoll_idle_time_ms_ = idle_time_ms;
72 sqpoll_thread_cpu_ = cpu;
73 return *this;
74 }
75
81 if (enable_sqpoll_ || enable_coop_taskrun_) {
82 throw std::logic_error(
83 "defer_taskrun cannot be enabled with sqpoll or coop_taskrun");
84 }
85 enable_defer_taskrun_ = true;
86 return *this;
87 }
88
93 Self &sq_size(size_t v) {
94 sq_size_ = v;
95 return *this;
96 }
97
102 Self &cq_size(size_t v) {
103 cq_size_ = v;
104 return *this;
105 }
106
113 Self &enable_attach_wq(Runtime &other) {
114 attach_wq_target_ = &other;
115 return *this;
116 }
117
123 if (enable_sqpoll_ || enable_defer_taskrun_) {
124 throw std::logic_error(
125 "coop_taskrun cannot be enabled with sqpoll or defer_taskrun");
126 }
127 enable_coop_taskrun_ = true;
128 return *this;
129 }
130
137 [[deprecated("Use enable_coop_taskrun() without parameters instead")]]
138 Self &enable_coop_taskrun([[maybe_unused]] bool taskrun_flag) {
140 return *this;
141 }
142
147 if (enable_sqe_mixed_) {
148 throw std::logic_error("sqe128 cannot be enabled with sqe_mixed");
149 }
150 enable_sqe128_ = true;
151 return *this;
152 }
153
157 Self &enable_cqe32() {
158 if (enable_cqe_mixed_) {
159 throw std::logic_error("cqe32 cannot be enabled with cqe_mixed");
160 }
161 enable_cqe32_ = true;
162 return *this;
163 }
164
165#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
170 if (enable_sqe128_) {
171 throw std::logic_error("sqe_mixed cannot be enabled with sqe128");
172 }
173 enable_sqe_mixed_ = true;
174 return *this;
175 }
176#endif
177
178#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
183 if (enable_cqe32_) {
184 throw std::logic_error("cqe_mixed cannot be enabled with cqe32");
185 }
186 enable_cqe_mixed_ = true;
187 return *this;
188 }
189#endif
190
191#if !IO_URING_CHECK_VERSION(2, 5) // >= 2.5
197 Self &enable_no_mmap(void *buf = nullptr, size_t buf_size = 0) {
198 enable_no_mmap_ = true;
199 no_mmap_buf_ = buf;
200 no_mmap_buf_size_ = buf_size;
201 return *this;
202 }
203#endif
204
205protected:
206 size_t event_interval_ = 61;
207 bool disable_register_ring_fd_ = false;
208 bool enable_iopoll_ = false;
209 bool enable_hybrid_iopoll_ = false;
210 bool enable_sqpoll_ = false;
211 size_t sqpoll_idle_time_ms_ = 1000;
212 std::optional<uint32_t> sqpoll_thread_cpu_ = std::nullopt;
213 bool enable_defer_taskrun_ = false;
214 size_t sq_size_ = 128;
215 size_t cq_size_ = 0; // 0 means default
216 Runtime *attach_wq_target_ = nullptr;
217 bool enable_coop_taskrun_ = false;
218 bool enable_sqe128_ = false;
219 bool enable_cqe32_ = false;
220 bool enable_sqe_mixed_ = false;
221 bool enable_cqe_mixed_ = false;
222 bool enable_no_mmap_ = false;
223 void *no_mmap_buf_ = nullptr;
224 size_t no_mmap_buf_size_ = 0;
225
226 friend class Runtime;
227};
228
229} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:76
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_sqe128()
See IORING_SETUP_SQE128.
Self & enable_attach_wq(Runtime &other)
See IORING_SETUP_ATTACH_WQ.
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 & enable_iopoll(bool hybrid=false)
See IORING_SETUP_IOPOLL.
Self & cq_size(size_t v)
Set CQ size.
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.