Skip to content

Commit

Permalink
add more options for executor
Browse files Browse the repository at this point in the history
Signed-off-by: liulanzheng <lanzheng.liulz@alibaba-inc.com>
  • Loading branch information
liulanzheng committed May 21, 2024
1 parent 24e35e7 commit 136ceb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 9 additions & 6 deletions common/executor/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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()) {}

Expand Down
10 changes: 9 additions & 1 deletion common/executor/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ limitations under the License.
#include <photon/thread/thread.h>

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 <
Expand Down

0 comments on commit 136ceb5

Please sign in to comment.