43 #include <boost/asio/placeholders.hpp>
44 #include <boost/bind/bind.hpp>
45 #include <boost/intrusive_ptr.hpp>
46 #include <boost/scoped_ptr.hpp>
47 #include <boost/function.hpp>
48 #include <boost/asio.hpp>
49 #include <boost/system/error_code.hpp>
53 using namespace boost::placeholders;
63 typedef boost::function<bool(
void)>
Handler;
64 typedef boost::function<void(std::string, std::string, std::string)>
67 Timer(boost::asio::io_context &service,
const std::string &name,
68 int task_id,
int task_instance,
bool delete_on_completion =
false);
84 bool Reschedule(
int time);
90 std::scoped_lock lock(mutex_);
91 return (state_ == Running);
95 std::scoped_lock lock(mutex_);
96 return (state_ == Fired);
104 std::scoped_lock lock(mutex_);
105 return (state_ == Cancelled);
109 std::scoped_lock lock(mutex_);
110 return (state_ == Cancelled || state_ ==
Init);
114 return delete_on_completion_;
117 int64_t GetElapsedTime()
const;
122 std::scoped_lock lock(mutex_);
123 if (handler_ && !handler_.empty()) {
135 friend class TimerTest;
149 void StartTimerTask(TimerPtr reference,
150 int time, uint32_t seq_no,
151 const boost::system::error_code &ec);
156 static int timer_task_id = -1;
158 if (timer_task_id == -1) {
160 timer_task_id = scheduler->
GetTaskId(
"timer::TimerTask");
162 return timer_task_id;
185 int prev = timer->
refcount_.fetch_sub(1);
205 static Timer *CreateTimer(boost::asio::io_context &service,
206 const std::string &name,
209 bool delete_on_completion =
false);
213 friend class TimerTest;
219 return lhs.get() < rhs.get();
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
int GetTaskId(const std::string &name)
static TaskScheduler * GetInstance()
static TimerSet timer_ref_
std::set< TimerPtr, TimerPtrCmp > TimerSet
boost::intrusive_ptr< Timer > TimerPtr
bool IsDeleteOnCompletion() const
void SetState(TimerState s)
boost::scoped_ptr< TimerImpl > impl_
ErrorHandler error_handler_
static int GetTimerInstanceId()
boost::intrusive_ptr< Timer > TimerPtr
virtual std::string Description()
boost::function< bool(void)> Handler
bool delete_on_completion_
boost::function< void(std::string, std::string, std::string)> ErrorHandler
std::atomic< int > refcount_
static int GetTimerTaskId()
bool operator()(const TimerPtr &lhs, const TimerPtr &rhs) const
void intrusive_ptr_add_ref(Timer *timer)
void intrusive_ptr_release(Timer *timer)