Skip to content

Commit

Permalink
Include ConcurrentScheduler separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Nov 23, 2020
1 parent 45c3e28 commit 6571a99
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 26 deletions.
1 change: 1 addition & 0 deletions benchmark/bench_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/bench_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/bench_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/bench_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/bench_http_server_cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/bench_http_server_fast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench_tddb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions benchmark/wget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions td/telegram/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions td/telegram/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion td/telegram/td_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tdactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tdactor/example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<void()> f) {
std::lock_guard<std::mutex> lock(at_finish_mutex_);
at_finish_.push_back(std::move(f));
}

} // namespace td
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,29 +85,21 @@ class ConcurrentScheduler : private Scheduler::Callback {
enum class State { Start, Run };
State state_ = State::Start;
std::mutex at_finish_mutex_;
std::vector<std::function<void()>> at_finish_; // can be used during destruction by Scheduler destructors
std::vector<unique_ptr<Scheduler>> schedulers_;
vector<std::function<void()>> at_finish_; // can be used during destruction by Scheduler destructors
vector<unique_ptr<Scheduler>> schedulers_;
std::atomic<bool> is_finished_{false};
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
std::vector<thread> threads_;
vector<td::thread> threads_;
#endif
#if TD_PORT_WINDOWS
unique_ptr<detail::Iocp> iocp_;
td::thread iocp_thread_;
#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<void()> f) override {
std::lock_guard<std::mutex> lock(at_finish_mutex_);
at_finish_.push_back(std::move(f));
}
void register_at_finish(std::function<void()> f) override;
};

} // namespace td
1 change: 0 additions & 1 deletion tdactor/td/actor/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions tdactor/test/actors_bugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tdactor/test/actors_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tdactor/test/actors_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tdactor/test/actors_workers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "td/utils/tests.h"

#include "td/actor/actor.h"
#include "td/actor/ConcurrentScheduler.h"

#include "td/utils/logging.h"

Expand Down
1 change: 1 addition & 0 deletions test/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/mtproto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/secret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/tdclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6571a99

Please sign in to comment.