From 1ac2dfef30d53183ade197fdac26e05720214a39 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 14 Sep 2022 15:06:52 +0300 Subject: [PATCH] Replace ConcurrentScheduler::init with constructor. --- benchmark/bench_actor.cpp | 9 +++---- benchmark/bench_db.cpp | 6 ++--- benchmark/bench_http.cpp | 3 +-- benchmark/bench_http_server.cpp | 3 +-- benchmark/bench_http_server_cheat.cpp | 3 +-- benchmark/bench_http_server_fast.cpp | 3 +-- benchmark/bench_tddb.cpp | 3 +-- benchmark/wget.cpp | 3 +-- td/telegram/Client.cpp | 7 +++--- td/telegram/cli.cpp | 3 +-- tdactor/example/example.cpp | 3 +-- tdactor/td/actor/ConcurrentScheduler.cpp | 2 +- tdactor/td/actor/ConcurrentScheduler.h | 2 +- tdactor/test/actors_bugs.cpp | 8 ++----- tdactor/test/actors_main.cpp | 15 ++++-------- tdactor/test/actors_simple.cpp | 30 ++++++++---------------- tdactor/test/actors_workers.cpp | 3 +-- test/db.cpp | 3 +-- test/mtproto.cpp | 21 ++++++----------- test/online.cpp | 3 +-- test/secret.cpp | 4 +--- test/tdclient.cpp | 3 +-- 22 files changed, 47 insertions(+), 93 deletions(-) diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index b3a04f592..afe94ca3c 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -46,10 +46,9 @@ class ActorTraits { } // namespace td class CreateActorBench final : public td::Benchmark { - td::ConcurrentScheduler scheduler_; + td::ConcurrentScheduler scheduler_{0, 0}; void start_up() final { - scheduler_.init(0); scheduler_.start(); } @@ -140,8 +139,7 @@ class RingBench final : public td::Benchmark { } void start_up() final { - scheduler_ = new td::ConcurrentScheduler(); - scheduler_->init(thread_n_); + scheduler_ = new td::ConcurrentScheduler(thread_n_, 0); actor_array_ = td::vector>(actor_n_); for (int i = 0; i < actor_n_; i++) { @@ -293,8 +291,7 @@ class QueryBench final : public td::Benchmark { }; void start_up() final { - scheduler_ = new td::ConcurrentScheduler(); - scheduler_->init(0); + scheduler_ = new td::ConcurrentScheduler(0, 0); server_ = scheduler_->create_actor_unsafe(0, "Server"); scheduler_->start(); diff --git a/benchmark/bench_db.cpp b/benchmark/bench_db.cpp index b257951c5..822a91593 100644 --- a/benchmark/bench_db.cpp +++ b/benchmark/bench_db.cpp @@ -29,7 +29,7 @@ template class TdKvBench final : public td::Benchmark { - td::ConcurrentScheduler sched; + td::ConcurrentScheduler sched{1, 0}; td::string name_; public: @@ -72,7 +72,6 @@ class TdKvBench final : public td::Benchmark { }; void start_up_n(int n) final { - sched.init(1); sched.create_actor_unsafe
(1, "Main", n).release(); } @@ -179,8 +178,7 @@ class SqliteKeyValueAsyncBench final : public td::Benchmark { td::unique_ptr sqlite_kv_async_; td::Status do_start_up() { - scheduler_ = td::make_unique(); - scheduler_->init(1); + scheduler_ = td::make_unique(1, 0); auto guard = scheduler_->get_main_guard(); diff --git a/benchmark/bench_http.cpp b/benchmark/bench_http.cpp index fe90d32a2..70fdb909c 100644 --- a/benchmark/bench_http.cpp +++ b/benchmark/bench_http.cpp @@ -66,8 +66,7 @@ class HttpClient final : public td::HttpOutboundConnection::Callback { int main() { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - auto scheduler = td::make_unique(); - scheduler->init(0); + auto scheduler = td::make_unique(0, 0); scheduler->create_actor_unsafe(0, "Client1").release(); scheduler->create_actor_unsafe(0, "Client2").release(); scheduler->start(); diff --git a/benchmark/bench_http_server.cpp b/benchmark/bench_http_server.cpp index 7ce892a48..33cde9ef8 100644 --- a/benchmark/bench_http_server.cpp +++ b/benchmark/bench_http_server.cpp @@ -74,8 +74,7 @@ class Server final : public td::TcpListener::Callback { int main() { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - auto scheduler = td::make_unique(); - scheduler->init(N, 0); + auto scheduler = td::make_unique(N, 0); scheduler->create_actor_unsafe(0, "Server").release(); scheduler->start(); while (scheduler->run_main(10)) { diff --git a/benchmark/bench_http_server_cheat.cpp b/benchmark/bench_http_server_cheat.cpp index 8661ba4c1..8bbd768b4 100644 --- a/benchmark/bench_http_server_cheat.cpp +++ b/benchmark/bench_http_server_cheat.cpp @@ -121,8 +121,7 @@ class Server final : public td::TcpListener::Callback { int main() { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - auto scheduler = td::make_unique(); - scheduler->init(N, 0); + auto scheduler = td::make_unique(N, 0); scheduler->create_actor_unsafe(0, "Server").release(); scheduler->start(); while (scheduler->run_main(10)) { diff --git a/benchmark/bench_http_server_fast.cpp b/benchmark/bench_http_server_fast.cpp index 1c272d96b..4b140422f 100644 --- a/benchmark/bench_http_server_fast.cpp +++ b/benchmark/bench_http_server_fast.cpp @@ -106,8 +106,7 @@ class Server final : public td::TcpListener::Callback { int main() { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - auto scheduler = td::make_unique(); - scheduler->init(N, 0); + auto scheduler = td::make_unique(N, 0); scheduler->create_actor_unsafe(0, "Server").release(); scheduler->start(); while (scheduler->run_main(10)) { diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index eb6880359..b41033c6e 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -87,8 +87,7 @@ class MessagesDbBench final : public td::Benchmark { std::shared_ptr messages_db_async_; td::Status do_start_up() { - scheduler_ = td::make_unique(); - scheduler_->init(1); + scheduler_ = td::make_unique(1, 0); auto guard = scheduler_->get_main_guard(); diff --git a/benchmark/wget.cpp b/benchmark/wget.cpp index 1fdfc2af1..5145f317f 100644 --- a/benchmark/wget.cpp +++ b/benchmark/wget.cpp @@ -23,8 +23,7 @@ int main(int argc, char *argv[]) { auto timeout = 10; auto ttl = 3; auto prefer_ipv6 = (argc > 2 && td::string(argv[2]) == "-6"); - auto scheduler = td::make_unique(); - scheduler->init(0); + auto scheduler = td::make_unique(0, 0); scheduler ->create_actor_unsafe(0, "Client", td::PromiseCreator::lambda([](td::Result> res) { diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index 00003d933..f9fcb5894 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -98,8 +98,7 @@ class ClientManager::Impl final { CHECK(concurrent_scheduler_ == nullptr); CHECK(options_.net_query_stats == nullptr); options_.net_query_stats = std::make_shared(); - concurrent_scheduler_ = make_unique(); - concurrent_scheduler_->init(0, 0); + concurrent_scheduler_ = make_unique(0, 0); concurrent_scheduler_->start(); } tds_[client_id] = @@ -354,8 +353,7 @@ class MultiImpl { static constexpr int32 ADDITIONAL_THREAD_COUNT = 3; explicit MultiImpl(std::shared_ptr net_query_stats) { - concurrent_scheduler_ = std::make_shared(); - concurrent_scheduler_->init(ADDITIONAL_THREAD_COUNT, 0); + concurrent_scheduler_ = std::make_shared(ADDITIONAL_THREAD_COUNT, 0); concurrent_scheduler_->start(); { @@ -423,6 +421,7 @@ class MultiImpl { static std::atomic current_id_; }; +constexpr int32 MultiImpl::ADDITIONAL_THREAD_COUNT; std::atomic MultiImpl::current_id_{1}; class MultiImplPool { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ec4fb0c6b..5c622950a 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5257,8 +5257,7 @@ void main(int argc, char **argv) { } { - ConcurrentScheduler scheduler; - scheduler.init(3); + ConcurrentScheduler scheduler(3, 0); class CreateClient final : public Actor { public: diff --git a/tdactor/example/example.cpp b/tdactor/example/example.cpp index fb5ea6507..8f182d835 100644 --- a/tdactor/example/example.cpp +++ b/tdactor/example/example.cpp @@ -36,8 +36,7 @@ class MainActor final : public td::Actor { }; int main() { - td::ConcurrentScheduler scheduler; - scheduler.init(4 /*thread_count*/, 0); + td::ConcurrentScheduler scheduler(4 /*thread_count*/, 0); scheduler.start(); { auto guard = scheduler.get_main_guard(); diff --git a/tdactor/td/actor/ConcurrentScheduler.cpp b/tdactor/td/actor/ConcurrentScheduler.cpp index eb4557452..f5ffe10a2 100644 --- a/tdactor/td/actor/ConcurrentScheduler.cpp +++ b/tdactor/td/actor/ConcurrentScheduler.cpp @@ -15,7 +15,7 @@ namespace td { -void ConcurrentScheduler::init(int32 additional_thread_count, uint64 thread_affinity_mask) { +ConcurrentScheduler::ConcurrentScheduler(int32 additional_thread_count, uint64 thread_affinity_mask) { #if TD_THREAD_UNSUPPORTED || TD_EVENTFD_UNSUPPORTED additional_thread_count = 0; #endif diff --git a/tdactor/td/actor/ConcurrentScheduler.h b/tdactor/td/actor/ConcurrentScheduler.h index f833848d2..490deb218 100644 --- a/tdactor/td/actor/ConcurrentScheduler.h +++ b/tdactor/td/actor/ConcurrentScheduler.h @@ -26,7 +26,7 @@ namespace td { class ConcurrentScheduler final : private Scheduler::Callback { public: - void init(int32 additional_thread_count, uint64 thread_affinity_mask = 0); + explicit ConcurrentScheduler(int32 additional_thread_count, uint64 thread_affinity_mask = 0); void finish_async() { schedulers_[0]->finish(); diff --git a/tdactor/test/actors_bugs.cpp b/tdactor/test/actors_bugs.cpp index 9f3841430..0720f0ed6 100644 --- a/tdactor/test/actors_bugs.cpp +++ b/tdactor/test/actors_bugs.cpp @@ -14,9 +14,7 @@ #include "td/utils/tests.h" TEST(MultiTimeout, bug) { - td::ConcurrentScheduler sched; - int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(0, 0); sched.start(); td::unique_ptr multi_timeout; @@ -91,9 +89,7 @@ class TimeoutManager final : public td::Actor { td::int32 TimeoutManager::count; TEST(MultiTimeout, Destroy) { - td::ConcurrentScheduler sched; - int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(0, 0); auto timeout_manager = sched.create_actor_unsafe(0, "TimeoutManager"); TimeoutManager *manager = timeout_manager.get().get_actor_unsafe(); diff --git a/tdactor/test/actors_main.cpp b/tdactor/test/actors_main.cpp index 4bb9ac54b..628b74a94 100644 --- a/tdactor/test/actors_main.cpp +++ b/tdactor/test/actors_main.cpp @@ -394,9 +394,8 @@ class SendToDead final : public td::Actor { TEST(Actors, send_to_dead) { //TODO: fix CHECK(storage_count_.load() == 0) return; - td::ConcurrentScheduler sched; int threads_n = 5; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe(0, "SendToDead").release(); sched.start(); @@ -407,9 +406,8 @@ TEST(Actors, send_to_dead) { } TEST(Actors, main_simple) { - td::ConcurrentScheduler sched; int threads_n = 3; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe(threads_n > 1 ? 1 : 0, "simple", threads_n).release(); sched.start(); @@ -420,9 +418,8 @@ TEST(Actors, main_simple) { } TEST(Actors, main) { - td::ConcurrentScheduler sched; int threads_n = 9; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe(threads_n > 1 ? 1 : 0, "MainQuery", threads_n).release(); sched.start(); @@ -446,9 +443,8 @@ class DoAfterStop final : public td::Actor { }; TEST(Actors, do_after_stop) { - td::ConcurrentScheduler sched; int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe(0, "DoAfterStop").release(); sched.start(); @@ -492,9 +488,8 @@ static void check_context() { } TEST(Actors, context_during_destruction) { - td::ConcurrentScheduler sched; int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); { auto guard = sched.get_main_guard(); diff --git a/tdactor/test/actors_simple.cpp b/tdactor/test/actors_simple.cpp index 58f14ac48..78d32d543 100644 --- a/tdactor/test/actors_simple.cpp +++ b/tdactor/test/actors_simple.cpp @@ -256,8 +256,7 @@ TEST(Actors, simple_migrate) { sb.clear(); sb2.clear(); - td::ConcurrentScheduler scheduler; - scheduler.init(2); + td::ConcurrentScheduler scheduler(2, 0); auto pong = scheduler.create_actor_unsafe(2, "Pong").release(); scheduler.create_actor_unsafe(1, "Ping", pong).release(); scheduler.start(); @@ -300,8 +299,7 @@ class OpenClose final : public td::Actor { }; TEST(Actors, open_close) { - td::ConcurrentScheduler scheduler; - scheduler.init(2); + td::ConcurrentScheduler scheduler(2, 0); int cnt = 10000; // TODO(perf) optimize scheduler.create_actor_unsafe(1, "A", cnt).release(); scheduler.create_actor_unsafe(2, "B", cnt).release(); @@ -425,8 +423,7 @@ class LinkTokenMasterActor final : public td::Actor { }; TEST(Actors, link_token) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); auto cnt = 100000; scheduler.create_actor_unsafe(0, "A", cnt).release(); scheduler.start(); @@ -485,8 +482,7 @@ class LaterMasterActor final : public td::Actor { TEST(Actors, later) { sb.clear(); - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "A").release(); scheduler.start(); while (scheduler.run_main(10)) { @@ -524,8 +520,7 @@ class MultiPromise1 final : public td::Actor { }; TEST(Actors, MultiPromise) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "A").release(); scheduler.start(); while (scheduler.run_main(10)) { @@ -546,8 +541,7 @@ class FastPromise final : public td::Actor { }; TEST(Actors, FastPromise) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "A").release(); scheduler.start(); while (scheduler.run_main(10)) { @@ -566,8 +560,7 @@ class StopInTeardown final : public td::Actor { }; TEST(Actors, stop_in_teardown) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "A").release(); scheduler.start(); while (scheduler.run_main(10)) { @@ -601,8 +594,7 @@ class AlwaysWaitForMailbox final : public td::Actor { }; TEST(Actors, always_wait_for_mailbox) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "A").release(); scheduler.start(); while (scheduler.run_main(10)) { @@ -612,8 +604,7 @@ TEST(Actors, always_wait_for_mailbox) { #if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED TEST(Actors, send_from_other_threads) { - td::ConcurrentScheduler scheduler; - scheduler.init(1); + td::ConcurrentScheduler scheduler(1, 0); int thread_n = 10; class Listener final : public td::Actor { public: @@ -680,8 +671,7 @@ class MultiPromiseSendClosureLaterTest final : public td::Actor { }; TEST(Actors, MultiPromiseSendClosureLater) { - td::ConcurrentScheduler scheduler; - scheduler.init(0); + td::ConcurrentScheduler scheduler(0, 0); scheduler.create_actor_unsafe(0, "MultiPromiseSendClosureLaterTest").release(); scheduler.start(); while (scheduler.run_main(1)) { diff --git a/tdactor/test/actors_workers.cpp b/tdactor/test/actors_workers.cpp index 748edd4e8..bac42e3fd 100644 --- a/tdactor/test/actors_workers.cpp +++ b/tdactor/test/actors_workers.cpp @@ -106,8 +106,7 @@ class Manager final : public td::Actor { }; static void test_workers(int threads_n, int workers_n, int queries_n, int query_size) { - td::ConcurrentScheduler sched; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); td::vector> workers; for (int i = 0; i < workers_n; i++) { diff --git a/test/db.cpp b/test/db.cpp index b51a8cf20..61757e989 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -684,8 +684,7 @@ TEST(DB, persistent_key_value) { int ref_cnt_; }; - td::ConcurrentScheduler sched; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe
(0, "Main", threads_n, &queries, &res).release(); sched.start(); while (sched.run_main(10)) { diff --git a/test/mtproto.cpp b/test/mtproto.cpp index f15c5ca10..89f5441ab 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -47,9 +47,8 @@ #include "td/utils/Time.h" TEST(Mtproto, GetHostByNameActor) { - td::ConcurrentScheduler sched; int threads_n = 1; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); int cnt = 1; td::vector> actors; @@ -139,9 +138,8 @@ TEST(Time, parse_http_date) { } TEST(Mtproto, config) { - td::ConcurrentScheduler sched; int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); int cnt = 1; { @@ -273,7 +271,6 @@ class Mtproto_ping final : public td::Test { using Test::Test; bool step() final { if (!is_inited_) { - sched_.init(0); sched_.create_actor_unsafe(0, "Pinger", get_default_ip_address(), &result_).release(); sched_.start(); is_inited_ = true; @@ -292,7 +289,7 @@ class Mtproto_ping final : public td::Test { private: bool is_inited_ = false; - td::ConcurrentScheduler sched_; + td::ConcurrentScheduler sched_{0, 0}; td::Status result_; }; td::RegisterTest mtproto_ping("Mtproto_ping"); @@ -416,7 +413,6 @@ class Mtproto_handshake final : public td::Test { using Test::Test; bool step() final { if (!is_inited_) { - sched_.init(0); sched_.create_actor_unsafe(0, "HandshakeTestActor", get_default_dc_id(), &result_).release(); sched_.start(); is_inited_ = true; @@ -435,7 +431,7 @@ class Mtproto_handshake final : public td::Test { private: bool is_inited_ = false; - td::ConcurrentScheduler sched_; + td::ConcurrentScheduler sched_{0, 0}; td::Status result_; }; td::RegisterTest mtproto_handshake("Mtproto_handshake"); @@ -484,9 +480,8 @@ class Socks5TestActor final : public td::Actor { TEST(Mtproto, socks5) { return; - td::ConcurrentScheduler sched; int threads_n = 0; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); sched.create_actor_unsafe(0, "Socks5TestActor").release(); sched.start(); @@ -640,7 +635,6 @@ class Mtproto_FastPing final : public td::Test { using Test::Test; bool step() final { if (!is_inited_) { - sched_.init(0); sched_.create_actor_unsafe(0, "FastPingTestActor", &result_).release(); sched_.start(); is_inited_ = true; @@ -659,7 +653,7 @@ class Mtproto_FastPing final : public td::Test { private: bool is_inited_ = false; - td::ConcurrentScheduler sched_; + td::ConcurrentScheduler sched_{0, 0}; td::Status result_; }; td::RegisterTest mtproto_fastping("Mtproto_FastPing"); @@ -676,9 +670,8 @@ TEST(Mtproto, Grease) { } TEST(Mtproto, TlsTransport) { - td::ConcurrentScheduler sched; int threads_n = 1; - sched.init(threads_n); + td::ConcurrentScheduler sched(threads_n, 0); { auto guard = sched.get_main_guard(); class RunTest final : public td::Actor { diff --git a/test/online.cpp b/test/online.cpp index f472c6ae8..6bcdcec83 100644 --- a/test/online.cpp +++ b/test/online.cpp @@ -617,8 +617,7 @@ int main(int argc, char **argv) { } SET_VERBOSITY_LEVEL(new_verbosity_level); - td::ConcurrentScheduler sched; - sched.init(4); + td::ConcurrentScheduler sched(4, 0); sched.create_actor_unsafe(0, "TestTd", std::move(test_options)).release(); sched.start(); while (sched.run_main(10)) { diff --git a/test/secret.cpp b/test/secret.cpp index 3c1d351ea..5a602fe85 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -999,9 +999,7 @@ void FakeSecretChatContext::on_read_message(int64, Promise<> promise) { TEST(Secret, go) { return; - ConcurrentScheduler sched; - int threads_n = 0; - sched.init(threads_n); + ConcurrentScheduler sched(0, 0); Status result; sched.create_actor_unsafe(0, "HandshakeTestActor", &result).release(); diff --git a/test/tdclient.cpp b/test/tdclient.cpp index d2a5a3afb..ca95fa4d8 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -832,7 +832,6 @@ class Tdclient_login final : public td::Test { using Test::Test; bool step() final { if (!is_inited_) { - sched_.init(4); sched_.create_actor_unsafe(0, "LoginTestActor", &result_).release(); sched_.start(); is_inited_ = true; @@ -852,7 +851,7 @@ class Tdclient_login final : public td::Test { private: bool is_inited_ = false; - td::ConcurrentScheduler sched_; + td::ConcurrentScheduler sched_{4, 0}; td::Status result_; }; //RegisterTest Tdclient_login("Tdclient_login");