11 #include "absl/container/flat_hash_set.h" 12 #include "absl/strings/string_view.h" 13 #include "base/arena.h" 14 #include "base/type_traits.h" 15 #include "base/RWSpinLock.h" 16 #include "util/uring/proactor.h" 22 template <
typename Func,
typename... Args>
23 using AcceptArgsCheck =
24 typename std::enable_if<base::is_invocable<Func, Args...>::value,
40 void Run(uint32_t ring_depth = 256);
70 template <
typename Func, AcceptArgsCheck<Func, Proactor*> = 0>
73 for (
unsigned i = 0; i < size(); ++i) {
77 context.
AsyncBrief([&context, func]()
mutable { func(&context); });
88 template <
typename Func, AcceptArgsCheck<Func,
unsigned, Proactor*> = 0>
91 for (
unsigned i = 0; i < size(); ++i) {
94 context.
AsyncBrief([&context, i, func]()
mutable { func(i, &context); });
104 template <
typename Func, AcceptArgsCheck<Func, Proactor*> = 0>
107 auto cb = [func = std::forward<Func>(func), bc](
Proactor* context)
mutable {
120 template <
typename Func, AcceptArgsCheck<Func,
unsigned, Proactor*> = 0>
123 auto cb = [func = std::forward<Func>(func), bc](
unsigned index,
125 func(index, context);
140 template <
typename Func, AcceptArgsCheck<Func,
unsigned, Proactor*> = 0>
143 [func = std::forward<Func>(func)](
unsigned i,
Proactor* context) {
144 ::boost::fibers::fiber(func, i, context).detach();
156 template <
typename Func, AcceptArgsCheck<Func, Proactor*> = 0>
159 ::boost::fibers::fiber(func, context).detach();
171 template <
typename Func, AcceptArgsCheck<Func,
unsigned, Proactor*> = 0>
174 auto cb = [func = std::forward<Func>(func), bc](
unsigned i,
191 template <
typename Func, AcceptArgsCheck<Func, Proactor*> = 0>
194 auto cb = [func = std::forward<Func>(func), bc](
Proactor* context)
mutable {
208 absl::string_view GetString(absl::string_view source);
212 void CheckRunningState();
214 std::unique_ptr<Proactor[]> proactor_;
217 std::atomic_uint_fast32_t next_io_context_{0};
220 folly::RWSpinLock str_lock_;
221 absl::flat_hash_set<absl::string_view> str_set_;
224 enum State { STOPPED, RUN } state_ = STOPPED;
227 constexpr
size_t foo =
sizeof(ProactorPool);
void AwaitOnAll(Func &&func)
Runs the funcion in all IO threads asynchronously. Blocks until all the asynchronous calls return.
void AsyncFiberOnAll(Func &&func)
Runs func in a fiber asynchronously. func must accept Proactor&. func may fiber-block.
void Stop()
Stops all io_context objects in the pool.
Proactor * GetNextProactor()
Get a Proactor to use. Thread-safe.
void AwaitFiberOnAll(Func &&func)
Runs func wrapped in fiber on all IO threads in parallel. func must accept Proactor&....
void AsyncBrief(Func &&brief)
void Run(uint32_t ring_depth=256)
void AsyncOnAll(Func &&func)
Runs func in all IO threads asynchronously.