21 tbb::mutex::scoped_lock lock(
timer_->mutex_);
39 if (
ec_ && !
timer_->error_handler_.empty()) {
41 std::string(
ec_.category().name()),
44 restart =
timer_->handler_();
52 }
else if (
timer_->delete_on_completion_) {
63 tbb::mutex::scoped_lock lock(
timer_->mutex_);
65 if (
timer_->timer_task_ !=
this) {
66 assert(!
timer_->timer_task_);
69 timer_->timer_task_ = NULL;
74 return timer_->Description();
79 boost::system::error_code
ec_;
83 Timer::Timer(boost::asio::io_context &service,
const std::string &name,
84 int task_id,
int task_instance,
bool delete_on_completion)
93 task_instance_(task_instance),
95 delete_on_completion_(delete_on_completion) {
109 tbb::mutex::scoped_lock lock(
mutex_);
124 boost::system::error_code ec;
125 impl_->expires_from_now(time, ec);
133 time,
seq_no_, boost::asio::placeholders::error));
151 tbb::mutex::scoped_lock lock(
mutex_);
173 const boost::system::error_code &ec) {
174 tbb::mutex::scoped_lock lock(
mutex_);
181 if (ec && ec.value() == boost::asio::error::operation_aborted) {
202 boost::asio::io_context &service,
const std::string &name,
203 int task_id,
int task_instance,
bool delete_on_completion) {
204 Timer *timer =
new Timer(service, name, task_id, task_instance,
205 delete_on_completion);
211 tbb::mutex::scoped_lock lock(
mutex_);
223 if (!timer || timer->
fired())
return false;
228 tbb::mutex::scoped_lock lock(
mutex_);
236 tbb::mutex::scoped_lock lock(
mutex_);
239 #if __cplusplus >= 201103L
240 elapsed = std::chrono::nanoseconds(
impl_->expires_from_now()).count();
242 elapsed = boost::chrono::nanoseconds(
impl_->expires_from_now()).count();
245 elapsed =
time_ - elapsed / 1000000;
int task_id_
The code path executed by the task.
tbb::atomic< int > refcount_
boost::intrusive_ptr< Timer > TimerPtr
void OnTaskCancel()
Called on task exit, if it is marked for cancellation. If the user wants to do any cleanup on task ca...
std::set< TimerPtr, TimerPtrCmp > TimerSet
TimerTask(TimerPtr timer, boost::system::error_code ec)
boost::function< bool(void)> Handler
bool IsDeleteOnCompletion() const
boost::system::error_code ec_
CancelReturnCode Cancel(Task *task)
Cancels a Task that can be in RUN/WAIT state. The caller needs to ensure that the task exists when Ca...
boost::scoped_ptr< TimerImpl > impl_
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
ErrorHandler error_handler_
bool task_cancelled() const
static TaskScheduler * GetInstance()
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq...
void SetState(TimerState s)
Timer(boost::asio::io_context &service, const std::string &name, int task_id, int task_instance, bool delete_on_completion=false)
DISALLOW_COPY_AND_ASSIGN(TimerTask)
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
boost::intrusive_ptr< Timer > TimerPtr
virtual std::string Description() const
boost::function< void(std::string, std::string, std::string)> ErrorHandler
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
static TimerSet timer_ref_
int task_instance_
The dataset id within a code path.
bool Reschedule(int time)
int64_t GetElapsedTime() const
Task is a wrapper over tbb::task to support policies.
static bool DeleteTimer(Timer *Timer)
static void AddTimer(Timer *Timer)
void StartTimerTask(TimerPtr reference, int time, uint32_t seq_no, const boost::system::error_code &ec)