From 136ceb5c1af39f2cdf0456809ab1e147b45059f0 Mon Sep 17 00:00:00 2001 From: liulanzheng Date: Tue, 21 May 2024 18:21:10 +0800 Subject: [PATCH] add more options for executor Signed-off-by: liulanzheng --- common/executor/executor.cpp | 15 +++++++++------ common/executor/executor.h | 10 +++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/executor/executor.cpp b/common/executor/executor.cpp index a3a65983..924bdab1 100644 --- a/common/executor/executor.cpp +++ b/common/executor/executor.cpp @@ -23,9 +23,11 @@ class Executor::ExecutorImpl { CBList queue; photon::ThreadPoolBase *pool; - ExecutorImpl(int init_ev, int init_io) { + ExecutorImpl(int init_ev, int init_io, const PhotonOptions& options, + const ExecutorQueueOption& queue_options) + : queue(queue_options.max_yield_turn, queue_options.max_yield_usec) { th.reset( - new std::thread(&ExecutorImpl::launch, this, init_ev, init_io)); + new std::thread(&ExecutorImpl::launch, this, init_ev, init_io, options)); } ExecutorImpl() {} @@ -75,15 +77,16 @@ class Executor::ExecutorImpl { pool = nullptr; } - void launch(int init_ev, int init_io) { - photon::init(init_ev, init_io); + void launch(int init_ev, int init_io, const PhotonOptions& options) { + photon::init(init_ev, init_io, options); DEFER(photon::fini()); do_loop(); } }; -Executor::Executor(int init_ev, int init_io) - : e(new Executor::ExecutorImpl(init_ev, init_io)) {} +Executor::Executor(int init_ev, int init_io, const PhotonOptions& options, + const ExecutorQueueOption& queue_options) + : e(new Executor::ExecutorImpl(init_ev, init_io, options, queue_options)) {} Executor::Executor(create_on_current_vcpu) : e(new Executor::ExecutorImpl()) {} diff --git a/common/executor/executor.h b/common/executor/executor.h index e93da7c7..7c681185 100644 --- a/common/executor/executor.h +++ b/common/executor/executor.h @@ -22,13 +22,21 @@ limitations under the License. #include namespace photon { + +struct ExecutorQueueOption { + uint64_t max_yield_turn; + uint64_t max_yield_usec; +}; + class Executor { public: class ExecutorImpl; ExecutorImpl *e; Executor(int init_ev = photon::INIT_EVENT_DEFAULT, - int init_io = photon::INIT_IO_DEFAULT); + int init_io = photon::INIT_IO_DEFAULT, + const PhotonOptions& options = {}, + const ExecutorQueueOption& queue_options = {-1UL, 1024}); ~Executor(); template <