Replace ConcurrentScheduler::init with constructor.

This commit is contained in:
levlam 2022-09-14 15:06:52 +03:00
parent 70e3586626
commit 1ac2dfef30
22 changed files with 47 additions and 93 deletions

View File

@ -46,10 +46,9 @@ class ActorTraits<TestActor> {
} // 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<td::ActorId<PassActor>>(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<ServerActor>(0, "Server");
scheduler_->start();

View File

@ -29,7 +29,7 @@
template <class KeyValueT>
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<Main>(1, "Main", n).release();
}
@ -179,8 +178,7 @@ class SqliteKeyValueAsyncBench final : public td::Benchmark {
td::unique_ptr<td::SqliteKeyValueAsyncInterface> sqlite_kv_async_;
td::Status do_start_up() {
scheduler_ = td::make_unique<td::ConcurrentScheduler>();
scheduler_->init(1);
scheduler_ = td::make_unique<td::ConcurrentScheduler>(1, 0);
auto guard = scheduler_->get_main_guard();

View File

@ -66,8 +66,7 @@ class HttpClient final : public td::HttpOutboundConnection::Callback {
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
auto scheduler = td::make_unique<td::ConcurrentScheduler>();
scheduler->init(0);
auto scheduler = td::make_unique<td::ConcurrentScheduler>(0, 0);
scheduler->create_actor_unsafe<HttpClient>(0, "Client1").release();
scheduler->create_actor_unsafe<HttpClient>(0, "Client2").release();
scheduler->start();

View File

@ -74,8 +74,7 @@ class Server final : public td::TcpListener::Callback {
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
auto scheduler = td::make_unique<td::ConcurrentScheduler>();
scheduler->init(N, 0);
auto scheduler = td::make_unique<td::ConcurrentScheduler>(N, 0);
scheduler->create_actor_unsafe<Server>(0, "Server").release();
scheduler->start();
while (scheduler->run_main(10)) {

View File

@ -121,8 +121,7 @@ class Server final : public td::TcpListener::Callback {
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
auto scheduler = td::make_unique<td::ConcurrentScheduler>();
scheduler->init(N, 0);
auto scheduler = td::make_unique<td::ConcurrentScheduler>(N, 0);
scheduler->create_actor_unsafe<Server>(0, "Server").release();
scheduler->start();
while (scheduler->run_main(10)) {

View File

@ -106,8 +106,7 @@ class Server final : public td::TcpListener::Callback {
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
auto scheduler = td::make_unique<td::ConcurrentScheduler>();
scheduler->init(N, 0);
auto scheduler = td::make_unique<td::ConcurrentScheduler>(N, 0);
scheduler->create_actor_unsafe<Server>(0, "Server").release();
scheduler->start();
while (scheduler->run_main(10)) {

View File

@ -87,8 +87,7 @@ class MessagesDbBench final : public td::Benchmark {
std::shared_ptr<td::MessagesDbAsyncInterface> messages_db_async_;
td::Status do_start_up() {
scheduler_ = td::make_unique<td::ConcurrentScheduler>();
scheduler_->init(1);
scheduler_ = td::make_unique<td::ConcurrentScheduler>(1, 0);
auto guard = scheduler_->get_main_guard();

View File

@ -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<td::ConcurrentScheduler>();
scheduler->init(0);
auto scheduler = td::make_unique<td::ConcurrentScheduler>(0, 0);
scheduler
->create_actor_unsafe<td::Wget>(0, "Client",
td::PromiseCreator::lambda([](td::Result<td::unique_ptr<td::HttpQuery>> res) {

View File

@ -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<NetQueryStats>();
concurrent_scheduler_ = make_unique<ConcurrentScheduler>();
concurrent_scheduler_->init(0, 0);
concurrent_scheduler_ = make_unique<ConcurrentScheduler>(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<NetQueryStats> net_query_stats) {
concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>();
concurrent_scheduler_->init(ADDITIONAL_THREAD_COUNT, 0);
concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>(ADDITIONAL_THREAD_COUNT, 0);
concurrent_scheduler_->start();
{
@ -423,6 +421,7 @@ class MultiImpl {
static std::atomic<uint32> current_id_;
};
constexpr int32 MultiImpl::ADDITIONAL_THREAD_COUNT;
std::atomic<uint32> MultiImpl::current_id_{1};
class MultiImplPool {

View File

@ -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:

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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<td::MultiTimeout> 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<TimeoutManager>(0, "TimeoutManager");
TimeoutManager *manager = timeout_manager.get().get_actor_unsafe();

View File

@ -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<SendToDead>(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<SimpleActor>(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<MainQueryActor>(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<DoAfterStop>(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();

View File

@ -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<Pong>(2, "Pong").release();
scheduler.create_actor_unsafe<Ping>(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<OpenClose>(1, "A", cnt).release();
scheduler.create_actor_unsafe<OpenClose>(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<LinkTokenMasterActor>(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<LaterMasterActor>(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<MultiPromise1>(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<FastPromise>(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<StopInTeardown>(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<AlwaysWaitForMailbox>(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<MultiPromiseSendClosureLaterTest>(0, "MultiPromiseSendClosureLaterTest").release();
scheduler.start();
while (scheduler.run_main(1)) {

View File

@ -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<td::ActorId<PowerWorker>> workers;
for (int i = 0; i < workers_n; i++) {

View File

@ -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<Main>(0, "Main", threads_n, &queries, &res).release();
sched.start();
while (sched.run_main(10)) {

View File

@ -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<td::ActorOwn<td::GetHostByNameActor>> 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<TestPingActor>(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("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<HandshakeTestActor>(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("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<Socks5TestActor>(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<FastPingTestActor>(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("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 {

View File

@ -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<TestTd>(0, "TestTd", std::move(test_options)).release();
sched.start();
while (sched.run_main(10)) {

View File

@ -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<Master>(0, "HandshakeTestActor", &result).release();

View File

@ -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<LoginTestActor>(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("Tdclient_login");