This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7654 from EOSIO/checktime_timer_only
exclusively use timer for checktime
- Loading branch information
Showing
13 changed files
with
218 additions
and
154 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 was deleted.
Oops, something went wrong.
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
27 changes: 0 additions & 27 deletions
27
libraries/chain/include/eosio/chain/checktime_timer_calibrate.hpp
This file was deleted.
Oops, something went wrong.
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
8 changes: 8 additions & 0 deletions
8
libraries/chain/include/eosio/chain/platform_timer_accuracy.hpp
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,8 @@ | ||
#pragma once | ||
|
||
namespace eosio { namespace chain { | ||
|
||
struct platform_timer; | ||
void compute_and_print_timer_accuracy(platform_timer& t); | ||
|
||
}} |
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,91 @@ | ||
#include <eosio/chain/platform_timer.hpp> | ||
#include <eosio/chain/platform_timer_accuracy.hpp> | ||
|
||
#include <fc/fwd_impl.hpp> | ||
#include <fc/log/logger_config.hpp> //set_os_thread_name() | ||
|
||
#include <boost/asio.hpp> | ||
|
||
#include <mutex> | ||
#include <thread> | ||
|
||
namespace eosio { namespace chain { | ||
|
||
//a thread is shared for all instances | ||
static std::mutex timer_ref_mutex; | ||
static unsigned refcount; | ||
static std::thread checktime_thread; | ||
static std::unique_ptr<boost::asio::io_service> checktime_ios; | ||
|
||
struct platform_timer::impl { | ||
std::unique_ptr<boost::asio::high_resolution_timer> timer; | ||
}; | ||
|
||
platform_timer::platform_timer() { | ||
static_assert(sizeof(impl) <= fwd_size); | ||
|
||
std::lock_guard guard(timer_ref_mutex); | ||
|
||
if(refcount++ == 0) { | ||
std::promise<void> p; | ||
checktime_thread = std::thread([&p]() { | ||
fc::set_os_thread_name("checktime"); | ||
checktime_ios = std::make_unique<boost::asio::io_service>(); | ||
boost::asio::io_service::work work(*checktime_ios); | ||
p.set_value(); | ||
|
||
checktime_ios->run(); | ||
}); | ||
p.get_future().get(); | ||
} | ||
|
||
my->timer = std::make_unique<boost::asio::high_resolution_timer>(*checktime_ios); | ||
|
||
//compute_and_print_timer_accuracy(*this); | ||
} | ||
|
||
platform_timer::~platform_timer() { | ||
stop(); | ||
if(std::lock_guard guard(timer_ref_mutex); --refcount == 0) { | ||
checktime_ios->stop(); | ||
checktime_thread.join(); | ||
checktime_ios.reset(); | ||
} | ||
} | ||
|
||
void platform_timer::start(fc::time_point tp) { | ||
if(tp == fc::time_point::maximum()) { | ||
expired = 0; | ||
return; | ||
} | ||
fc::microseconds x = tp.time_since_epoch() - fc::time_point::now().time_since_epoch(); | ||
if(x.count() <= 0) | ||
expired = 1; | ||
else { | ||
#if 0 | ||
std::promise<void> p; | ||
checktime_ios->post([&p,this]() { | ||
expired = 0; | ||
p.set_value(); | ||
}); | ||
p.get_future().get(); | ||
#endif | ||
expired = 0; | ||
my->timer->expires_after(std::chrono::microseconds((int)x.count())); | ||
my->timer->async_wait([this](const boost::system::error_code& ec) { | ||
if(ec) | ||
return; | ||
expired = 1; | ||
}); | ||
} | ||
} | ||
|
||
void platform_timer::stop() { | ||
if(expired) | ||
return; | ||
|
||
my->timer->cancel(); | ||
expired = 1; | ||
} | ||
|
||
}} |
Oops, something went wrong.