41 #include "../Activity.hpp" 42 #include "../Logger.hpp" 43 #include "../os/fosi.h" 53 return this->getThread()->getPeriod() == 0;
74 wake_up_time = std::numeric_limits<Time>::max();
75 for (TimerIds::iterator it = mtimers.begin(); it != mtimers.end(); ++it) {
76 if ( it->expires != 0 && it->expires < wake_up_time ) {
77 wake_up_time = it->expires;
78 next_timer_id = it - mtimers.begin();
83 if ( wake_up_time == std::numeric_limits<Time>::max() )
84 ret = mcond.wait( mmutex );
86 ret = mcond.wait_until( mmutex, wake_up_time );
98 if ( next_timer_id <
int(mtimers.size()) ) {
100 TimerIds::iterator tim = mtimers.begin() + next_timer_id;
103 tim->expires += tim->period;
114 mtimers[next_timer_id].expired.broadcast();
121 timeout( next_timer_id );
131 for (
TimerId i = 0; i < (int) mtimers.size(); ++i) {
138 : mThread(0), mdo_quit(false)
141 if (scheduler != -1) {
166 if ( timer_id < 0 || timer_id >=
int(
mtimers.size()) || period < 0.0)
168 log(
Error) <<
"Invalid timer id or period" << endlog();
176 mtimers[timer_id].expires = due_time;
185 if ( timer_id < 0 || timer_id >=
int(
mtimers.size()) || wait_time < 0.0)
187 log(
Error) <<
"Invalid timer id or wait time" << endlog();
196 mtimers[timer_id].expires = due_time;
206 if (timer_id < 0 || timer_id >=
int(
mtimers.size()) )
208 log(
Error) <<
"Invalid timer id" << endlog();
211 return mtimers[timer_id].expires != 0;
217 if (timer_id < 0 || timer_id >=
int(
mtimers.size()) )
219 log(
Error) <<
"Invalid timer id" << endlog();
233 if (timer_id < 0 || timer_id >=
int(
mtimers.size()) )
235 log(
Error) <<
"Invalid timer id" << endlog();
240 mtimers[timer_id].expired.broadcast();
247 if (timer_id < 0 || timer_id >=
int(
mtimers.size()) )
249 log(
Error) <<
"Invalid timer id" << endlog();
252 if (
mtimers[timer_id].expires == 0)
return false;
260 if (timer_id < 0 || timer_id >=
int(
mtimers.size()) )
262 log(
Error) <<
"Invalid timer id" << endlog();
265 if (
mtimers[timer_id].expires == 0)
return false;
267 return mtimers[timer_id].expired.wait_until(
mmutex, abs_time);
void finalize()
The method that will be called after the last periodical execution of step() ( or non periodical exec...
bool initialize()
The method that will be called before the first periodical execution of step() ( or non periodical ex...
TimeService::Seconds timeRemaining(TimerId timer_id) const
Returns the remaining time before this timer elapses.
bool startTimer(TimerId timer_id, Seconds period)
Start a periodic timer which starts first over period seconds and then every period seconds...
bool breakLoop()
This method is called by the framework to break out of the loop() method.
Seconds nsecs_to_Seconds(const nsecs ns)
NANO_TIME rtos_get_time_ns(void)
Get "system" time in nanoseconds.
bool killTimer(TimerId timer_id)
Disable an armed timer.
base::ActivityInterface * mThread
int TimerId
A positive numeric ID representing a timer.
bool isArmed(TimerId timer_id) const
Check if a given timer id is armed.
bool arm(TimerId timer_id, Seconds wait_time)
Arm a timer to fire once over wait_time seconds.
void step()
The method that will be periodically executed when this class is run in a periodic thread...
void setMaxTimers(TimerId max)
Change the maximum number of timers in this object.
Timer(TimerId max_timers, int scheduler=-1, int priority=0)
Create a timer object which can hold max_timers timers.
An Activity is an object that represents a thread.
bool waitForUntil(RTT::os::Timer::TimerId id, nsecs abs_time)
Wait for a timer to expire with timeout.
void loop()
The method that will be executed once when this class is run in a non periodic thread.
nsecs Seconds_to_nsecs(const Seconds s)
virtual bool start()=0
Start the activity.
bool waitFor(RTT::os::Timer::TimerId id)
Wait for a timer to expire.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
long long nsecs
nanoseconds as a signed long long.
virtual void timeout(TimerId timer_id)
This function is called each time an armed or periodic timer expires.
void broadcast()
Wake all threads that are blocking in wait() or wait_until().
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...