39 #include <tbb/mutex.h>
41 #include <boost/asio/placeholders.hpp>
42 #include <boost/bind.hpp>
43 #include <boost/intrusive_ptr.hpp>
44 #include <boost/scoped_ptr.hpp>
45 #include <boost/function.hpp>
46 #include <boost/asio.hpp>
47 #include <boost/system/error_code.hpp>
60 typedef boost::function<bool(void)>
Handler;
61 typedef boost::function<void(std::string, std::string, std::string)>
64 Timer(boost::asio::io_context &service,
const std::string &name,
65 int task_id,
int task_instance,
bool delete_on_completion =
false);
87 tbb::mutex::scoped_lock lock(
mutex_);
92 tbb::mutex::scoped_lock lock(
mutex_);
101 tbb::mutex::scoped_lock lock(
mutex_);
106 tbb::mutex::scoped_lock lock(
mutex_);
119 tbb::mutex::scoped_lock lock(
mutex_);
147 int time, uint32_t seq_no,
148 const boost::system::error_code &ec);
153 static int timer_task_id = -1;
155 if (timer_task_id == -1) {
157 timer_task_id = scheduler->
GetTaskId(
"timer::TimerTask");
159 return timer_task_id;
182 int prev = timer->
refcount_.fetch_and_decrement();
203 const std::string &name,
206 bool delete_on_completion =
false);
216 return lhs.get() < rhs.get();
int intrusive_ptr_add_ref(const AsPath *cpath)
tbb::atomic< int > refcount_
boost::intrusive_ptr< Timer > TimerPtr
bool operator()(const TimerPtr &lhs, const TimerPtr &rhs) const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
std::set< TimerPtr, TimerPtrCmp > TimerSet
boost::function< bool(void)> Handler
bool IsDeleteOnCompletion() const
virtual std::string Description()
static int GetTimerTaskId()
int GetTaskId(const std::string &name)
boost::scoped_ptr< TimerImpl > impl_
ErrorHandler error_handler_
static TaskScheduler * GetInstance()
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)
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)
friend void intrusive_ptr_add_ref(Timer *timer)
friend void intrusive_ptr_release(Timer *timer)
boost::intrusive_ptr< Timer > TimerPtr
boost::function< void(std::string, std::string, std::string)> ErrorHandler
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
static TimerSet timer_ref_
void intrusive_ptr_release(const AsPath *cpath)
bool Reschedule(int time)
int64_t GetElapsedTime() const
bool delete_on_completion_
static int GetTimerInstanceId()
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)