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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
9 additions and
10 deletions
-
include/libp2p/protocol/common/asio/asio_scheduler.hpp
-
src/protocol/common/asio/asio_scheduler.cpp
|
|
@ -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_; |
|
|
|
|
|
@ -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() { |
|
|
|