ConcurrentScheduler: do not create extra scheduler
GitOrigin-RevId: edfc73084f7417913b58e338f4e0f21e28014215
This commit is contained in:
parent
cdb5aa38a7
commit
482e4d7af6
|
@ -29,7 +29,7 @@ const sleep = ms => new Promise(res => setTimeout(res, ms));
|
||||||
class TdClient {
|
class TdClient {
|
||||||
/**
|
/**
|
||||||
* @callback TdClient~updateCallback
|
* @callback TdClient~updateCallback
|
||||||
* @param {Object} The update.
|
* @param {Object} update The update.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,13 +35,13 @@ void ConcurrentScheduler::init(int32 threads_n) {
|
||||||
// +1 for extra scheduler for IOCP and send_closure from unrelated threads
|
// +1 for extra scheduler for IOCP and send_closure from unrelated threads
|
||||||
// It will know about other schedulers
|
// It will know about other schedulers
|
||||||
// Other schedulers will have no idea about its existence
|
// Other schedulers will have no idea about its existence
|
||||||
int32 extra_scheduler = 1;
|
extra_scheduler_ = 1;
|
||||||
#if TD_THREAD_UNSUPPORTED || TD_EVENTFD_UNSUPPORTED
|
#if TD_THREAD_UNSUPPORTED || TD_EVENTFD_UNSUPPORTED
|
||||||
extra_scheduler = 0;
|
extra_scheduler_ = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
schedulers_.resize(threads_n + extra_scheduler);
|
schedulers_.resize(threads_n + extra_scheduler_);
|
||||||
for (int32 i = 0; i < threads_n + extra_scheduler; i++) {
|
for (int32 i = 0; i < threads_n + extra_scheduler_; i++) {
|
||||||
auto &sched = schedulers_[i];
|
auto &sched = schedulers_[i];
|
||||||
sched = make_unique<Scheduler>();
|
sched = make_unique<Scheduler>();
|
||||||
|
|
||||||
|
@ -75,12 +75,10 @@ void ConcurrentScheduler::test_one_thread_run() {
|
||||||
void ConcurrentScheduler::start() {
|
void ConcurrentScheduler::start() {
|
||||||
CHECK(state_ == State::Start);
|
CHECK(state_ == State::Start);
|
||||||
is_finished_.store(false, std::memory_order_relaxed);
|
is_finished_.store(false, std::memory_order_relaxed);
|
||||||
set_thread_id(0);
|
|
||||||
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
|
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
|
||||||
for (size_t i = 1; i < schedulers_.size(); i++) {
|
for (size_t i = 1; i + extra_scheduler_ < schedulers_.size(); i++) {
|
||||||
auto &sched = schedulers_[i];
|
auto &sched = schedulers_[i];
|
||||||
threads_.push_back(td::thread([&, tid = i]() {
|
threads_.push_back(td::thread([&]() {
|
||||||
set_thread_id(static_cast<int32>(tid));
|
|
||||||
#if TD_PORT_WINDOWS
|
#if TD_PORT_WINDOWS
|
||||||
td::detail::Iocp::Guard iocp_guard(iocp_.get());
|
td::detail::Iocp::Guard iocp_guard(iocp_.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -95,6 +95,7 @@ class ConcurrentScheduler : private Scheduler::Callback {
|
||||||
unique_ptr<detail::Iocp> iocp_;
|
unique_ptr<detail::Iocp> iocp_;
|
||||||
td::thread iocp_thread_;
|
td::thread iocp_thread_;
|
||||||
#endif
|
#endif
|
||||||
|
int extra_scheduler_;
|
||||||
|
|
||||||
void on_finish() override {
|
void on_finish() override {
|
||||||
is_finished_.store(true, std::memory_order_relaxed);
|
is_finished_.store(true, std::memory_order_relaxed);
|
||||||
|
|
Reference in New Issue
Block a user