Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mock_time.cpp
Go to the documentation of this file.
1
#include <
fc/mock_time.hpp
>
2
#include <thread>
3
4
namespace
fc
{
5
6
bool
mock_time_traits::mock_enabled_ =
false
;
7
const
boost::posix_time::ptime mock_time_traits::epoch_{ boost::gregorian::date( 1970, 1, 1 ) };
8
std::atomic<int64_t> mock_time_traits::now_{};
9
10
mock_time_traits::time_type
mock_time_traits::now
() noexcept {
11
return
epoch_ + boost::posix_time::microseconds( now_.load() );
12
}
13
14
void
mock_time_traits::set_now
(
time_type
t ) {
15
fc::time_point
now
(
fc::microseconds
( (t - epoch_).total_microseconds() ) );
16
set_now
(
now
);
17
}
18
19
void
mock_time_traits::set_now
(
const
fc::time_point
& now ) {
20
now_ =
now
.time_since_epoch().count();
21
if
( !mock_enabled_ ) mock_enabled_ =
true
;
22
23
// After modifying the clock, we need to sleep the thread to give the io_service
24
// the opportunity to poll and notice the change in clock time.
25
// See to_posix_duration()
26
std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) );
27
}
28
29
fc::time_point
mock_time_traits::fc_now
() {
30
return
fc::time_point
(
fc::microseconds
( (
mock_time_traits::now
() - epoch_ ).total_microseconds() ) );
31
}
32
33
}
//namespace fc
fc::microseconds
Definition
time.hpp:11
fc::mock_time_traits::fc_now
static fc::time_point fc_now()
Definition
mock_time.cpp:29
fc::mock_time_traits::now
static time_type now() noexcept
Definition
mock_time.cpp:10
fc::mock_time_traits::set_now
static void set_now(time_type t)
Definition
mock_time.cpp:14
fc::mock_time_traits::time_type
source_traits::time_type time_type
Definition
mock_time.hpp:12
fc::time_point
Definition
time.hpp:42
mock_time.hpp
fc
namespace sysio::chain
Definition
authority.cpp:3
libraries
fc
src
mock_time.cpp
Generated by
1.12.0