17 #define epicsExportSharedSymbols 22 namespace epics {
namespace pvData {
34 ,thread(threadName,priority,this)
40 return lhs->timeToRun < rhs->timeToRun;
47 assert(!timerCallback->onList);
50 temp.push_back(timerCallback);
52 timerCallback->onList =
true;
63 if(!timerCallback->onList)
return false;
65 timerCallback->onList =
false;
68 for(queue_t::iterator it(queue.begin()), end(queue.end()); it != end; ++it)
71 if(cur.get() == timerCallback.get()) {
77 throw std::logic_error(
"Timer::cancel() onList==true, but not found");
83 return timerCallback->onList;
91 epicsTime now(epicsTime::getCurrent());
102 now = epicsTime::getCurrent();
104 }
else if((waitfor = queue.front()->timeToRun - now) <= 0) {
108 work.swap(queue.front());
109 work->onList =
false;
118 if(work->period > 0.0 && alive) {
119 work->timeToRun += work->period;
131 now = epicsTime::getCurrent();
154 for(;!temp.empty(); temp.pop_front()) {
156 head->onList =
false;
157 head->timerStopped();
173 epicsTime now(epicsTime::getCurrent());
178 if(timerCallback->onList) {
179 throw std::logic_error(
string(
"already queued"));
184 timerCallback->timerStopped();
188 timerCallback->timeToRun = now + delay;
189 timerCallback->period = period;
191 addElement(timerCallback);
192 wakeup = waiting && queue.front()==timerCallback;
201 epicsTime now(epicsTime::getCurrent());
203 for(queue_t::const_iterator it(queue.begin()), end(queue.end()); it!=end; ++it) {
205 o <<
"timeToRun " << (nodeToCall->timeToRun - now)
206 <<
" period " << nodeToCall->period <<
"\n";
void close()
Prevent new callbacks from being scheduled, and cancel pending callbacks.
void schedulePeriodic(TimerCallbackPtr const &timerCallback, double delay, double period)
#define assert(exp)
Declare that a condition should be true.
bool cancel(TimerCallbackPtr const &timerCallback)
void dump(std::ostream &o) const
TODO only here because of the Lockable.
A lock for multithreading.
bool isScheduled(TimerCallbackPtr const &timerCallback) const
std::ostream & operator<<(std::ostream &o, const Field &f)
bool operator()(const TimerCallbackPtr &lhs, const TimerCallbackPtr &rhs)
Support for delayed or periodic callback execution.
std::tr1::shared_ptr< TimerCallback > TimerCallbackPtr
void scheduleAfterDelay(TimerCallbackPtr const &timerCallback, double delay)
C++ and C descriptions for a thread.
Timer(std::string threadName, ThreadPriority priority)