Rename scheduler_ field to concurrent_scheduler_.

GitOrigin-RevId: c760e0fab2ed8c1d93d32260f4a1d9b9b70359d9
This commit is contained in:
levlam 2018-09-14 21:40:33 +03:00
parent 7b2684b3ed
commit c081f6c79c

View File

@ -34,7 +34,7 @@ class Client::Impl final {
Response receive(double timeout) { Response receive(double timeout) {
if (!requests_.empty()) { if (!requests_.empty()) {
auto guard = scheduler_->get_current_guard(); auto guard = concurrent_scheduler_->get_current_guard();
for (auto &request : requests_) { for (auto &request : requests_) {
send_closure_later(td_, &Td::request, request.id, std::move(request.function)); send_closure_later(td_, &Td::request, request.id, std::move(request.function));
} }
@ -42,7 +42,7 @@ class Client::Impl final {
} }
if (responses_.empty()) { if (responses_.empty()) {
scheduler_->run_main(0); concurrent_scheduler_->run_main(0);
} }
if (!responses_.empty()) { if (!responses_.empty()) {
auto result = std::move(responses_.front()); auto result = std::move(responses_.front());
@ -58,25 +58,25 @@ class Client::Impl final {
Impl &operator=(Impl &&) = delete; Impl &operator=(Impl &&) = delete;
~Impl() { ~Impl() {
{ {
auto guard = scheduler_->get_current_guard(); auto guard = concurrent_scheduler_->get_current_guard();
td_.reset(); td_.reset();
} }
while (!closed_) { while (!closed_) {
scheduler_->run_main(0); concurrent_scheduler_->run_main(0);
} }
scheduler_.reset(); concurrent_scheduler_.reset();
} }
private: private:
std::deque<Response> responses_; std::deque<Response> responses_;
std::vector<Request> requests_; std::vector<Request> requests_;
std::unique_ptr<ConcurrentScheduler> scheduler_; std::unique_ptr<ConcurrentScheduler> concurrent_scheduler_;
ActorOwn<Td> td_; ActorOwn<Td> td_;
bool closed_ = false; bool closed_ = false;
void init() { void init() {
scheduler_ = std::make_unique<ConcurrentScheduler>(); concurrent_scheduler_ = std::make_unique<ConcurrentScheduler>();
scheduler_->init(0); concurrent_scheduler_->init(0);
class Callback : public TdCallback { class Callback : public TdCallback {
public: public:
explicit Callback(Impl *client) : client_(client) { explicit Callback(Impl *client) : client_(client) {
@ -95,8 +95,8 @@ class Client::Impl final {
private: private:
Impl *client_; Impl *client_;
}; };
td_ = scheduler_->create_actor_unsafe<Td>(0, "Td", make_unique<Callback>(this)); td_ = concurrent_scheduler_->create_actor_unsafe<Td>(0, "Td", make_unique<Callback>(this));
scheduler_->start(); concurrent_scheduler_->start();
} }
}; };
@ -117,7 +117,7 @@ class Client::Impl final {
return; return;
} }
auto guard = scheduler_->get_send_guard(); auto guard = concurrent_scheduler_->get_send_guard();
send_closure(td_, &Td::request, request.id, std::move(request.function)); send_closure(td_, &Td::request, request.id, std::move(request.function));
} }
@ -135,14 +135,14 @@ class Client::Impl final {
Impl(Impl &&) = delete; Impl(Impl &&) = delete;
Impl &operator=(Impl &&) = delete; Impl &operator=(Impl &&) = delete;
~Impl() { ~Impl() {
auto guard = scheduler_->get_send_guard(); auto guard = concurrent_scheduler_->get_send_guard();
td_.reset(); td_.reset();
scheduler_thread_.join(); scheduler_thread_.join();
} }
private: private:
std::shared_ptr<OutputQueue> output_queue_; std::shared_ptr<OutputQueue> output_queue_;
std::shared_ptr<ConcurrentScheduler> scheduler_; std::shared_ptr<ConcurrentScheduler> concurrent_scheduler_;
int output_queue_ready_cnt_{0}; int output_queue_ready_cnt_{0};
thread scheduler_thread_; thread scheduler_thread_;
std::atomic<bool> receive_lock_{false}; std::atomic<bool> receive_lock_{false};
@ -151,8 +151,8 @@ class Client::Impl final {
void init() { void init() {
output_queue_ = std::make_shared<OutputQueue>(); output_queue_ = std::make_shared<OutputQueue>();
output_queue_->init(); output_queue_->init();
scheduler_ = std::make_shared<ConcurrentScheduler>(); concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>();
scheduler_->init(3); concurrent_scheduler_->init(3);
class Callback : public TdCallback { class Callback : public TdCallback {
public: public:
explicit Callback(std::shared_ptr<OutputQueue> output_queue) : output_queue_(std::move(output_queue)) { explicit Callback(std::shared_ptr<OutputQueue> output_queue) : output_queue_(std::move(output_queue)) {
@ -170,13 +170,13 @@ class Client::Impl final {
private: private:
std::shared_ptr<OutputQueue> output_queue_; std::shared_ptr<OutputQueue> output_queue_;
}; };
td_ = scheduler_->create_actor_unsafe<Td>(0, "Td", std::make_unique<Callback>(output_queue_)); td_ = concurrent_scheduler_->create_actor_unsafe<Td>(0, "Td", std::make_unique<Callback>(output_queue_));
scheduler_->start(); concurrent_scheduler_->start();
scheduler_thread_ = thread([scheduler = scheduler_] { scheduler_thread_ = thread([scheduler = concurrent_scheduler_] {
while (scheduler->run_main(10)) { while (concurrent_scheduler->run_main(10)) {
} }
scheduler->finish(); concurrent_scheduler->finish();
}); });
} }