Browse Source

Hotfix/old sch and construction (#139)

* trying to fix injector-based construction of old asio scheduler
* fix injector-based construction of old asio scheduler #2
pull/142/head
art-gor 4 years ago
committed by GitHub
parent
commit
fb9e3901b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      include/libp2p/protocol/common/asio/asio_scheduler.hpp
  2. 15
      src/protocol/common/asio/asio_scheduler.cpp

4
include/libp2p/protocol/common/asio/asio_scheduler.hpp

@ -14,7 +14,7 @@ namespace libp2p::protocol {
class AsioScheduler : public Scheduler {
public:
AsioScheduler(const std::shared_ptr<boost::asio::io_context> &io,
AsioScheduler(std::shared_ptr<boost::asio::io_context> io,
SchedulerConfig config);
~AsioScheduler() override;
@ -28,7 +28,7 @@ namespace libp2p::protocol {
void onImmediate();
std::weak_ptr<boost::asio::io_context> io_;
std::shared_ptr<boost::asio::io_context> io_;
Ticks interval_;
boost::asio::deadline_timer timer_;
boost::posix_time::ptime started_;

15
src/protocol/common/asio/asio_scheduler.cpp

@ -9,7 +9,7 @@
namespace libp2p::protocol {
AsioScheduler::AsioScheduler(const std::shared_ptr<boost::asio::io_context> &io,
AsioScheduler::AsioScheduler(std::shared_ptr<boost::asio::io_context> io,
SchedulerConfig config)
: io_(io),
interval_(config.period_msec),
@ -28,8 +28,10 @@ namespace libp2p::protocol {
AsioScheduler::~AsioScheduler() {
*canceled_ = true;
if (!io_.expired()) {
try {
timer_.cancel();
} catch (...) {
// may throw
}
};
@ -41,18 +43,15 @@ namespace libp2p::protocol {
void AsioScheduler::scheduleImmediate() {
if (!immediate_cb_scheduled_) {
immediate_cb_scheduled_ = true;
auto io = io_.lock();
if (io) io->post(immediate_cb_);
io_->post(immediate_cb_);
}
}
void AsioScheduler::onTimer() {
pulse(false);
if (!io_.expired()) {
timer_.expires_at(timer_.expires_at()
timer_.expires_at(timer_.expires_at()
+ boost::posix_time::milliseconds(interval_));
timer_.async_wait(timer_cb_);
}
timer_.async_wait(timer_cb_);
}
void AsioScheduler::onImmediate() {

Loading…
Cancel
Save