so we can schedule an event with real_clock::time_point. timer should
wait using a mono_time, but user might want to pass a
real_clock::time_point to it when, for instance, scheduling a task which
should be performed in future at a specified time. in this case, we need
to convert the real_clock::time_point to a "known" time_point.
Signed-off-by: Kefu Chai <kchai@redhat.com>
return callback;
}
+Context* SafeTimer::add_event_at(ceph::real_clock::time_point when, Context *callback)
+{
+ ceph_assert(ceph_mutex_is_locked(lock));
+ // convert from real_clock to mono_clock
+ auto mono_now = ceph::mono_clock::now();
+ auto real_now = ceph::real_clock::now();
+ const auto delta = when - real_now;
+ const auto mono_atime = (mono_now +
+ std::chrono::ceil<clock_t::duration>(delta));
+ return add_event_at(mono_atime, callback);
+}
+
bool SafeTimer::cancel_event(Context *callback)
{
ceph_assert(ceph_mutex_is_locked(lock));
Context* add_event_after(ceph::timespan duration, Context *callback);
Context* add_event_after(double seconds, Context *callback);
Context* add_event_at(clock_t::time_point when, Context *callback);
-
+ Context* add_event_at(ceph::real_clock::time_point when, Context *callback);
/* Cancel an event.
* Call with the event_lock LOCKED
*