This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor block streaming method (processing is done in grpc thread) (#…
…2181) Signed-off-by: Igor Egorov <igor@soramitsu.co.jp>
- Loading branch information
Igor Egorov
authored
Mar 21, 2019
1 parent
5d1db98
commit f8efa83
Showing
3 changed files
with
114 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef IROHA_RUN_LOOP_HANDLER_HPP | ||
#define IROHA_RUN_LOOP_HANDLER_HPP | ||
|
||
#include <condition_variable> | ||
|
||
#include <rxcpp/rx.hpp> | ||
|
||
namespace iroha { | ||
namespace schedulers { | ||
|
||
inline void handleEvents(rxcpp::composite_subscription &subscription, | ||
rxcpp::schedulers::run_loop &run_loop) { | ||
std::condition_variable wait_cv; | ||
|
||
run_loop.set_notify_earlier_wakeup( | ||
[&wait_cv](const auto &) { wait_cv.notify_one(); }); | ||
|
||
std::mutex wait_mutex; | ||
std::unique_lock<std::mutex> lock(wait_mutex); | ||
while (subscription.is_subscribed() or not run_loop.empty()) { | ||
while (not run_loop.empty() | ||
and run_loop.peek().when <= run_loop.now()) { | ||
run_loop.dispatch(); | ||
} | ||
|
||
if (run_loop.empty()) { | ||
wait_cv.wait(lock, [&run_loop, &subscription]() { | ||
return not subscription.is_subscribed() or not run_loop.empty(); | ||
}); | ||
} else { | ||
wait_cv.wait_until(lock, run_loop.peek().when); | ||
} | ||
} | ||
} | ||
} // namespace schedulers | ||
} // namespace iroha | ||
|
||
#endif // IROHA_RUN_LOOP_HANDLER_HPP |