17 template <
typename CLOCK_T>
18 class generic_check_schedule {
20 typedef CLOCK_T clock_type;
21 typedef typename clock_type::time_point_type time_point_type;
22 typedef typename clock_type::time_duration_type time_duration_type;
27 bool next_check_known_;
28 double start_fraction_;
30 time_duration_type min_check_;
31 time_duration_type max_check_;
33 time_point_type start_time_;
34 time_point_type last_check_time_;
36 time_duration_type next_check_;
44 generic_check_schedule(
double tmin,
double tmax)
46 next_check_known_(false),
61 generic_check_schedule(
double tmin,
double tmax,
const clock_type& clock)
63 next_check_known_(false),
74 if (!next_check_known_)
return true;
75 time_point_type now = clock_.now_time();
76 return clock_.time_diff(now, last_check_time_) > next_check_;
80 void update(
double fraction)
82 time_point_type now = clock_.now_time();
85 if (!next_check_known_)
88 start_fraction_ = fraction;
89 next_check_known_=
true;
92 if (fraction > start_fraction_)
95 time_duration_type old_check = next_check_;
96 next_check_ = 0.25 * (1 - fraction)
97 * clock_.time_diff(now, start_time_) / (fraction - start_fraction_);
99 if( next_check_ > 2*old_check ) next_check_ = 2 * old_check;
100 if( next_check_ < min_check_ ) next_check_ = min_check_;
101 if( next_check_ > max_check_ ) next_check_ = max_check_;
104 next_check_ = min_check_;
106 last_check_time_ = now;
112 class posix_wall_clock {
115 typedef std::time_t time_point_type;
118 typedef double time_duration_type;
121 static time_point_type now_time() {
return std::time(0); }
124 static time_duration_type time_diff(time_point_type t1, time_point_type t0)
126 return std::difftime(t1, t0);
detail::generic_check_schedule< detail::posix_wall_clock > check_schedule