This is Unofficial EPICS BASE Doxygen Site
timerQueue Class Reference

#include "timerPrivate.h"

+ Inheritance diagram for timerQueue:
+ Collaboration diagram for timerQueue:

Public Member Functions

 timerQueue (epicsTimerQueueNotify &notify)
 
virtual ~timerQueue ()
 
epicsTimer & createTimer ()
 
epicsTimerForCcreateTimerForC (epicsTimerCallback pCallback, void *pArg)
 
double process (const epicsTime &currentTime)
 
void show (unsigned int level) const
 

Friends

class timer
 
struct epicsTimerForC
 

Detailed Description

Definition at line 88 of file timerPrivate.h.

Constructor & Destructor Documentation

timerQueue::timerQueue ( epicsTimerQueueNotify &  notify)

Definition at line 26 of file timerQueue.cpp.

26  :
27  mutex(__FILE__, __LINE__),
28  notify ( notifyIn ),
29  pExpireTmr ( 0 ),
30  processThread ( 0 ),
31  exceptMsgTimeStamp (
32  epicsTime :: getCurrent () - exceptMsgMinPeriod ),
33  cancelPending ( false )
34 {
35 }
timerQueue::~timerQueue ( )
virtual

Definition at line 37 of file timerQueue.cpp.

38 {
39  timer *pTmr;
40  while ( ( pTmr = this->timerList.get () ) ) {
41  pTmr->curState = timer::stateLimbo;
42  }
43 }
T * get()
Definition: tsDLList.h:261

Member Function Documentation

epicsTimer & timerQueue::createTimer ( )

Definition at line 204 of file timerQueue.cpp.

205 {
206  return * new ( this->timerFreeList ) timer ( * this );
207 }
epicsTimerForC & timerQueue::createTimerForC ( epicsTimerCallback  pCallback,
void *  pArg 
)

Definition at line 209 of file timerQueue.cpp.

210 {
211  return * new ( this->timerForCFreeList ) epicsTimerForC ( *this, pCallback, pArg );
212 }
double timerQueue::process ( const epicsTime &  currentTime)

Definition at line 78 of file timerQueue.cpp.

79 {
80  epicsGuard < epicsMutex > guard ( this->mutex );
81 
82  if ( this->pExpireTmr ) {
83  // if some other thread is processing the queue
84  // (or if this is a recursive call)
85  timer * pTmr = this->timerList.first ();
86  if ( pTmr ) {
87  double delay = pTmr->exp - currentTime;
88  if ( delay < 0.0 ) {
89  delay = 0.0;
90  }
91  return delay;
92  }
93  else {
94  return DBL_MAX;
95  }
96  }
97 
98  //
99  // Tag current epired tmr so that we can detect if call back
100  // is in progress when canceling the timer.
101  //
102  if ( this->timerList.first () ) {
103  if ( currentTime >= this->timerList.first ()->exp ) {
104  this->pExpireTmr = this->timerList.first ();
105  this->timerList.remove ( *this->pExpireTmr );
106  this->pExpireTmr->curState = timer::stateActive;
107  this->processThread = epicsThreadGetIdSelf ();
108 # ifdef DEBUG
109  this->pExpireTmr->show ( 0u );
110 # endif
111  }
112  else {
113  double delay = this->timerList.first ()->exp - currentTime;
114  debugPrintf ( ( "no activity process %f to next\n", delay ) );
115  return delay;
116  }
117  }
118  else {
119  return DBL_MAX;
120  }
121 
122 # ifdef DEBUG
123  unsigned N = 0u;
124 # endif
125 
126  double delay = DBL_MAX;
127  while ( true ) {
128  epicsTimerNotify *pTmpNotify = this->pExpireTmr->pNotify;
129  this->pExpireTmr->pNotify = 0;
130  epicsTimerNotify::expireStatus expStat ( epicsTimerNotify::noRestart );
131 
132  {
133  epicsGuardRelease < epicsMutex > unguard ( guard );
134 
135  debugPrintf ( ( "%5u expired \"%s\" with error %f sec\n",
136  N++, typeid ( this->pExpireTmr->notify ).name (),
137  currentTime - this->pExpireTmr->exp ) );
138  try {
139  expStat = pTmpNotify->expire ( currentTime );
140  }
141  catch ( std::exception & except ) {
142  printExceptMsg ( except.what (), typeid ( except ) );
143  }
144  catch ( ... ) {
145  printExceptMsg ( "non-standard exception", typeid ( void ) );
146  }
147  }
148 
149  //
150  // only restart if they didnt cancel() the timer
151  // while the call back was running
152  //
153  if ( this->cancelPending ) {
154  // 1) if another thread is canceling then cancel() waits for
155  // the event below
156  // 2) if this thread is canceling in the timer callback then
157  // dont touch timer or notify here because the cancel might
158  // have occurred because they destroyed the timer in the
159  // callback
160  this->cancelPending = false;
161  this->cancelBlockingEvent.signal ();
162  }
163  else {
164  this->pExpireTmr->curState = timer::stateLimbo;
165  if ( this->pExpireTmr->pNotify ) {
166  // pNotify was cleared above so if it is valid now we know that
167  // someone has started the timer from another thread and that
168  // predominates over the restart parameters from expire.
169  this->pExpireTmr->privateStart (
170  *this->pExpireTmr->pNotify, this->pExpireTmr->exp );
171  }
172  else if ( expStat.restart() ) {
173  // restart as nec
174  this->pExpireTmr->privateStart (
175  *pTmpNotify, currentTime + expStat.expirationDelay() );
176  }
177  }
178  this->pExpireTmr = 0;
179 
180  if ( this->timerList.first () ) {
181  if ( currentTime >= this->timerList.first ()->exp ) {
182  this->pExpireTmr = this->timerList.first ();
183  this->timerList.remove ( *this->pExpireTmr );
184  this->pExpireTmr->curState = timer::stateActive;
185 # ifdef DEBUG
186  this->pExpireTmr->show ( 0u );
187 # endif
188  }
189  else {
190  delay = this->timerList.first ()->exp - currentTime;
191  this->processThread = 0;
192  break;
193  }
194  }
195  else {
196  this->processThread = 0;
197  delay = DBL_MAX;
198  break;
199  }
200  }
201  return delay;
202 }
void show(unsigned int level) const
Definition: timer.cpp:186
void remove(T &item)
Definition: tsDLList.h:219
#define debugPrintf(argsInParen)
Definition: iocinf.h:30
T * first(void) const
Definition: tsDLList.h:190
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
void timerQueue::show ( unsigned int  level) const

Definition at line 214 of file timerQueue.cpp.

215 {
216  epicsGuard < epicsMutex > locker ( this->mutex );
217  printf ( "epicsTimerQueue with %u items pending\n", this->timerList.count () );
218  if ( level >= 1u ) {
219  tsDLIterConst < timer > iter = this->timerList.firstIter ();
220  while ( iter.valid () ) {
221  iter->show ( level - 1u );
222  ++iter;
223  }
224  }
225 }
void show(unsigned int level) const
Definition: timer.cpp:186
tsDLIterConst< T > firstIter() const
Definition: tsDLList.h:459
#define printf
Definition: epicsStdio.h:41
unsigned count() const
Definition: tsDLList.h:181
bool valid() const
Definition: tsDLList.h:506

Friends And Related Function Documentation

friend struct epicsTimerForC
friend

Definition at line 113 of file timerPrivate.h.

friend class timer
friend

Definition at line 112 of file timerPrivate.h.


The documentation for this class was generated from the following files: