From 6571a99b4555824606b3fecb20ad5993d1515b12 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 23 Nov 2020 03:24:36 +0300 Subject: [PATCH] Include ConcurrentScheduler separately. --- benchmark/bench_actor.cpp | 1 + benchmark/bench_db.cpp | 1 + benchmark/bench_http.cpp | 1 + benchmark/bench_http_server.cpp | 1 + benchmark/bench_http_server_cheat.cpp | 1 + benchmark/bench_http_server_fast.cpp | 1 + benchmark/bench_tddb.cpp | 2 +- benchmark/wget.cpp | 1 + td/telegram/Client.cpp | 1 + td/telegram/cli.cpp | 1 + td/telegram/td_emscripten.cpp | 2 +- tdactor/CMakeLists.txt | 6 +++--- tdactor/example/example.cpp | 1 + .../actor/{impl => }/ConcurrentScheduler.cpp | 19 ++++++++++++------ .../td/actor/{impl => }/ConcurrentScheduler.h | 20 ++++++------------- tdactor/td/actor/actor.h | 1 - tdactor/test/actors_bugs.cpp | 1 + tdactor/test/actors_main.cpp | 1 + tdactor/test/actors_simple.cpp | 1 + tdactor/test/actors_workers.cpp | 1 + test/db.cpp | 1 + test/mtproto.cpp | 1 + test/secret.cpp | 1 + test/tdclient.cpp | 1 + 24 files changed, 42 insertions(+), 26 deletions(-) rename tdactor/td/actor/{impl => }/ConcurrentScheduler.cpp (92%) rename tdactor/td/actor/{impl => }/ConcurrentScheduler.h (82%) diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index 32ca52f0e..d6f257102 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -7,6 +7,7 @@ #include "td/utils/benchmark.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" diff --git a/benchmark/bench_db.cpp b/benchmark/bench_db.cpp index bdc3bad81..9b5d548c6 100644 --- a/benchmark/bench_db.cpp +++ b/benchmark/bench_db.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/db/binlog/Binlog.h" #include "td/db/binlog/ConcurrentBinlog.h" diff --git a/benchmark/bench_http.cpp b/benchmark/bench_http.cpp index 22ab30f8f..479db4f40 100644 --- a/benchmark/bench_http.cpp +++ b/benchmark/bench_http.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/net/HttpOutboundConnection.h" #include "td/net/HttpQuery.h" diff --git a/benchmark/bench_http_server.cpp b/benchmark/bench_http_server.cpp index 89b4e4ef7..948b795f3 100644 --- a/benchmark/bench_http_server.cpp +++ b/benchmark/bench_http_server.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/net/HttpHeaderCreator.h" #include "td/net/HttpInboundConnection.h" diff --git a/benchmark/bench_http_server_cheat.cpp b/benchmark/bench_http_server_cheat.cpp index 9e8639881..7d1d46b69 100644 --- a/benchmark/bench_http_server_cheat.cpp +++ b/benchmark/bench_http_server_cheat.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/net/HttpHeaderCreator.h" #include "td/net/HttpInboundConnection.h" diff --git a/benchmark/bench_http_server_fast.cpp b/benchmark/bench_http_server_fast.cpp index c180c7856..2592a4d4f 100644 --- a/benchmark/bench_http_server_fast.cpp +++ b/benchmark/bench_http_server_fast.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/net/HttpHeaderCreator.h" #include "td/net/HttpQuery.h" diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index 953e3aa3c..33427055f 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -11,7 +11,7 @@ #include "td/telegram/ServerMessageId.h" #include "td/telegram/UserId.h" -#include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/db/SqliteConnectionSafe.h" diff --git a/benchmark/wget.cpp b/benchmark/wget.cpp index 7aa596d10..d1f32612c 100644 --- a/benchmark/wget.cpp +++ b/benchmark/wget.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/net/HttpQuery.h" diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index 97f86383a..0072a01ce 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -10,6 +10,7 @@ #include "td/telegram/TdCallback.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/utils/common.h" #include "td/utils/crypto.h" diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7775fea9f..945c40581 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "memprof/memprof.h" diff --git a/td/telegram/td_emscripten.cpp b/td/telegram/td_emscripten.cpp index 0cedf79e7..a7c7193da 100644 --- a/td/telegram/td_emscripten.cpp +++ b/td/telegram/td_emscripten.cpp @@ -4,7 +4,7 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/telegram/td_json_client.h" #include "td/telegram/td_log.h" diff --git a/tdactor/CMakeLists.txt b/tdactor/CMakeLists.txt index 58f0fb0a4..3cec195fa 100644 --- a/tdactor/CMakeLists.txt +++ b/tdactor/CMakeLists.txt @@ -6,11 +6,13 @@ endif() #SOURCE SETS set(TDACTOR_SOURCE - td/actor/impl/ConcurrentScheduler.cpp + td/actor/ConcurrentScheduler.cpp td/actor/impl/Scheduler.cpp td/actor/MultiPromise.cpp td/actor/Timeout.cpp + td/actor/actor.h + td/actor/ConcurrentScheduler.h td/actor/impl/Actor-decl.h td/actor/impl/Actor.h td/actor/impl/ActorId-decl.h @@ -19,7 +21,6 @@ set(TDACTOR_SOURCE td/actor/impl/ActorInfo.h td/actor/impl/EventFull-decl.h td/actor/impl/EventFull.h - td/actor/impl/ConcurrentScheduler.h td/actor/impl/Event.h td/actor/impl/Scheduler-decl.h td/actor/impl/Scheduler.h @@ -29,7 +30,6 @@ set(TDACTOR_SOURCE td/actor/SignalSlot.h td/actor/SleepActor.h td/actor/Timeout.h - td/actor/actor.h ) set(TDACTOR_TEST_SOURCE diff --git a/tdactor/example/example.cpp b/tdactor/example/example.cpp index e02f0ae36..a247754a4 100644 --- a/tdactor/example/example.cpp +++ b/tdactor/example/example.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/utils/logging.h" #include "td/utils/Time.h" diff --git a/tdactor/td/actor/impl/ConcurrentScheduler.cpp b/tdactor/td/actor/ConcurrentScheduler.cpp similarity index 92% rename from tdactor/td/actor/impl/ConcurrentScheduler.cpp rename to tdactor/td/actor/ConcurrentScheduler.cpp index e32de3be2..1b1e70093 100644 --- a/tdactor/td/actor/impl/ConcurrentScheduler.cpp +++ b/tdactor/td/actor/ConcurrentScheduler.cpp @@ -4,12 +4,7 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include "td/actor/impl/ConcurrentScheduler.h" - -#include "td/actor/impl/Actor.h" -#include "td/actor/impl/ActorId.h" -#include "td/actor/impl/ActorInfo.h" -#include "td/actor/impl/Scheduler.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/utils/ExitGuard.h" #include "td/utils/MpscPollableQueue.h" @@ -175,4 +170,16 @@ void ConcurrentScheduler::finish() { state_ = State::Start; } +void ConcurrentScheduler::on_finish() { + is_finished_.store(true, std::memory_order_relaxed); + for (auto &it : schedulers_) { + it->wakeup(); + } +} + +void ConcurrentScheduler::register_at_finish(std::function f) { + std::lock_guard lock(at_finish_mutex_); + at_finish_.push_back(std::move(f)); +} + } // namespace td diff --git a/tdactor/td/actor/impl/ConcurrentScheduler.h b/tdactor/td/actor/ConcurrentScheduler.h similarity index 82% rename from tdactor/td/actor/impl/ConcurrentScheduler.h rename to tdactor/td/actor/ConcurrentScheduler.h index ae5f85419..2fae89a8b 100644 --- a/tdactor/td/actor/impl/ConcurrentScheduler.h +++ b/tdactor/td/actor/ConcurrentScheduler.h @@ -6,7 +6,7 @@ // #pragma once -#include "td/actor/impl/Scheduler-decl.h" +#include "td/actor/actor.h" #include "td/utils/common.h" #include "td/utils/port/thread.h" @@ -85,11 +85,11 @@ class ConcurrentScheduler : private Scheduler::Callback { enum class State { Start, Run }; State state_ = State::Start; std::mutex at_finish_mutex_; - std::vector> at_finish_; // can be used during destruction by Scheduler destructors - std::vector> schedulers_; + vector> at_finish_; // can be used during destruction by Scheduler destructors + vector> schedulers_; std::atomic is_finished_{false}; #if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED - std::vector threads_; + vector threads_; #endif #if TD_PORT_WINDOWS unique_ptr iocp_; @@ -97,17 +97,9 @@ class ConcurrentScheduler : private Scheduler::Callback { #endif int32 extra_scheduler_; - void on_finish() override { - is_finished_.store(true, std::memory_order_relaxed); - for (auto &it : schedulers_) { - it->wakeup(); - } - } + void on_finish() override; - void register_at_finish(std::function f) override { - std::lock_guard lock(at_finish_mutex_); - at_finish_.push_back(std::move(f)); - } + void register_at_finish(std::function f) override; }; } // namespace td diff --git a/tdactor/td/actor/actor.h b/tdactor/td/actor/actor.h index c5761d6a7..9c89debcd 100644 --- a/tdactor/td/actor/actor.h +++ b/tdactor/td/actor/actor.h @@ -9,6 +9,5 @@ #include "td/actor/impl/Actor.h" #include "td/actor/impl/ActorId.h" #include "td/actor/impl/ActorInfo.h" -#include "td/actor/impl/ConcurrentScheduler.h" #include "td/actor/impl/EventFull.h" #include "td/actor/impl/Scheduler.h" diff --git a/tdactor/test/actors_bugs.cpp b/tdactor/test/actors_bugs.cpp index a08cb3865..62adfa019 100644 --- a/tdactor/test/actors_bugs.cpp +++ b/tdactor/test/actors_bugs.cpp @@ -10,6 +10,7 @@ #include "td/utils/tests.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/Timeout.h" using namespace td; diff --git a/tdactor/test/actors_main.cpp b/tdactor/test/actors_main.cpp index e98f338fe..cdd70020a 100644 --- a/tdactor/test/actors_main.cpp +++ b/tdactor/test/actors_main.cpp @@ -7,6 +7,7 @@ #include "td/utils/tests.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" diff --git a/tdactor/test/actors_simple.cpp b/tdactor/test/actors_simple.cpp index 709a8bc65..0ac4cdf05 100644 --- a/tdactor/test/actors_simple.cpp +++ b/tdactor/test/actors_simple.cpp @@ -7,6 +7,7 @@ #include "td/utils/tests.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/MultiPromise.h" #include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" diff --git a/tdactor/test/actors_workers.cpp b/tdactor/test/actors_workers.cpp index 7e0ec23fb..1be818e19 100644 --- a/tdactor/test/actors_workers.cpp +++ b/tdactor/test/actors_workers.cpp @@ -7,6 +7,7 @@ #include "td/utils/tests.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/utils/logging.h" diff --git a/test/db.cpp b/test/db.cpp index 35a6b8e63..3577c8585 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -18,6 +18,7 @@ #include "td/db/TsSeqKeyValue.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/utils/base64.h" #include "td/utils/common.h" diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 394f9ae47..873933291 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -27,6 +27,7 @@ #include "td/net/TransparentProxy.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/utils/base64.h" diff --git a/test/secret.cpp b/test/secret.cpp index 2020ff4c2..4ddbcb933 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -14,6 +14,7 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/db/binlog/BinlogInterface.h" diff --git a/test/tdclient.cpp b/test/tdclient.cpp index ffbf85e0b..46f731d4e 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -12,6 +12,7 @@ #include "td/telegram/td_api.h" #include "td/actor/actor.h" +#include "td/actor/ConcurrentScheduler.h" #include "td/actor/PromiseFuture.h" #include "td/utils/base64.h"