This is Unofficial EPICS BASE Doxygen Site
timerPrivate.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2015 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /*
10  * Author Jeffrey O. Hill
11  * johill@lanl.gov
12  * 505 665 1831
13  */
14 
15 #ifndef epicsTimerPrivate_h
16 #define epicsTimerPrivate_h
17 
18 #include <typeinfo>
19 
20 #include "tsFreeList.h"
21 #include "epicsSingleton.h"
22 #include "tsDLList.h"
23 #include "epicsTimer.h"
24 #include "compilerDependencies.h"
25 
26 #ifdef DEBUG
27 # define debugPrintf(ARGSINPAREN) printf ARGSINPAREN
28 #else
29 # define debugPrintf(ARGSINPAREN)
30 #endif
31 
32 template < class T > class epicsGuard;
33 
34 class timer : public epicsTimer, public tsDLNode < timer > {
35 public:
36  void destroy ();
37  void start ( class epicsTimerNotify &, const epicsTime & );
38  void start ( class epicsTimerNotify &, double delaySeconds );
39  void cancel ();
40  expireInfo getExpireInfo () const;
41  void show ( unsigned int level ) const;
42  void * operator new ( size_t size, tsFreeList < timer, 0x20 > & );
43  epicsPlacementDeleteOperator (( void *, tsFreeList < timer, 0x20 > & ))
44 protected:
45  timer ( class timerQueue & );
46  ~timer ();
48 private:
49  enum state { statePending = 45, stateActive = 56, stateLimbo = 78 };
50  epicsTime exp; // experation time
51  state curState; // current state
52  epicsTimerNotify * pNotify; // callback
53  void privateStart ( epicsTimerNotify & notify, const epicsTime & );
54  timer & operator = ( const timer & );
55  // Visual C++ .net appears to require operator delete if
56  // placement operator delete is defined? I smell a ms rat
57  // because if I declare placement new and delete, but
58  // comment out the placement delete definition there are
59  // no undefined symbols.
60  void operator delete ( void * );
61  friend class timerQueue;
62 };
63 
64 struct epicsTimerForC : public epicsTimerNotify, public timer {
65 public:
66  void destroy ();
67 protected:
68  epicsTimerForC ( timerQueue &, epicsTimerCallback, void *pPrivateIn );
69  ~epicsTimerForC ();
70  void * operator new ( size_t size, tsFreeList < epicsTimerForC, 0x20 > & );
71  epicsPlacementDeleteOperator (( void *, tsFreeList < epicsTimerForC, 0x20 > & ))
72 private:
73  epicsTimerCallback pCallBack;
74  void * pPrivate;
75  expireStatus expire ( const epicsTime & currentTime );
76  epicsTimerForC & operator = ( const epicsTimerForC & );
77  // Visual C++ .net appears to require operator delete if
78  // placement operator delete is defined? I smell a ms rat
79  // because if I declare placement new and delete, but
80  // comment out the placement delete definition there are
81  // no undefined symbols.
82  void operator delete ( void * );
83  friend class timerQueue;
84 };
85 
86 using std :: type_info;
87 
88 class timerQueue : public epicsTimerQueue {
89 public:
90  timerQueue ( epicsTimerQueueNotify &notify );
91  virtual ~timerQueue ();
92  epicsTimer & createTimer ();
93  epicsTimerForC & createTimerForC ( epicsTimerCallback pCallback, void *pArg );
94  double process ( const epicsTime & currentTime );
95  void show ( unsigned int level ) const;
96 private:
97  tsFreeList < timer, 0x20 > timerFreeList;
98  tsFreeList < epicsTimerForC, 0x20 > timerForCFreeList;
99  mutable epicsMutex mutex;
100  epicsEvent cancelBlockingEvent;
101  tsDLList < timer > timerList;
102  epicsTimerQueueNotify & notify;
103  timer * pExpireTmr;
104  epicsThreadId processThread;
105  epicsTime exceptMsgTimeStamp;
106  bool cancelPending;
107  static const double exceptMsgMinPeriod;
108  void printExceptMsg ( const char * pName,
109  const type_info & type );
110  timerQueue ( const timerQueue & );
111  timerQueue & operator = ( const timerQueue & );
112  friend class timer;
113  friend struct epicsTimerForC;
114 };
115 
117 public:
119 protected:
120  virtual ~timerQueueActiveMgrPrivate () = 0;
121 private:
122  unsigned referenceCount;
123  friend class timerQueueActiveMgr;
124 };
125 
126 class timerQueueActiveMgr;
127 
128 class timerQueueActive : public epicsTimerQueueActive,
129  public epicsThreadRunable, public epicsTimerQueueNotify,
131 public:
133  timerQueueActive ( RefMgr &, bool okToShare, unsigned priority );
134  void start ();
135  epicsTimer & createTimer ();
136  epicsTimerForC & createTimerForC ( epicsTimerCallback pCallback, void *pArg );
137  void show ( unsigned int level ) const;
138  bool sharingOK () const;
139  unsigned threadPriority () const;
140 protected:
141  ~timerQueueActive ();
142  RefMgr _refMgr;
143 private:
145  epicsEvent rescheduleEvent;
146  epicsEvent exitEvent;
147  epicsThread thread;
148  const double sleepQuantum;
149  bool okToShare;
150  int exitFlag; // use atomic ops
151  bool terminateFlag;
152  void run ();
153  void reschedule ();
154  double quantum ();
155  void _printLastChanceExceptionMessage (
156  const char * pExceptionTypeName,
157  const char * pExceptionContext );
158  epicsTimerQueue & getEpicsTimerQueue ();
160  timerQueueActive & operator = ( const timerQueueActive & );
161 };
162 
164 public:
168  epicsTimerQueueActiveForC & allocate ( RefThis &, bool okToShare,
169  unsigned threadPriority = epicsThreadPriorityMin + 10 );
170  void release ( epicsTimerQueueActiveForC & );
171 private:
175  timerQueueActiveMgr & operator = ( const timerQueueActiveMgr & );
176 };
177 
179 
180 class timerQueuePassive : public epicsTimerQueuePassive {
181 public:
182  timerQueuePassive ( epicsTimerQueueNotify & );
183  epicsTimer & createTimer ();
184  epicsTimerForC & createTimerForC ( epicsTimerCallback pCallback, void *pArg );
185  void show ( unsigned int level ) const;
186  double process ( const epicsTime & currentTime );
187 protected:
189  ~timerQueuePassive ();
190  epicsTimerQueue & getEpicsTimerQueue ();
192  timerQueuePassive & operator = ( const timerQueuePassive & );
193 };
194 
196  public epicsTimerQueueNotify, public timerQueuePassive {
197 public:
201  void * pPrivate );
202  void destroy ();
203 protected:
205 private:
206  epicsTimerQueueNotifyReschedule pRescheduleCallback;
207  epicsTimerQueueNotifyQuantum pSleepQuantumCallback;
208  void * pPrivate;
210  void reschedule ();
211  double quantum ();
212 };
213 
215  public tsDLNode < epicsTimerQueueActiveForC > {
216 public:
217  epicsTimerQueueActiveForC ( RefMgr &, bool okToShare, unsigned priority );
218  void release ();
219  void * operator new ( size_t );
220  void operator delete ( void * );
221 protected:
222  virtual ~epicsTimerQueueActiveForC ();
223 private:
225  epicsTimerQueueActiveForC & operator = ( const epicsTimerQueueActiveForC & );
226 };
227 
228 inline bool timerQueueActive::sharingOK () const
229 {
230  return this->okToShare;
231 }
232 
233 inline unsigned timerQueueActive::threadPriority () const
234 {
235  return thread.getPriority ();
236 }
237 
238 inline void * timer::operator new ( size_t size,
239  tsFreeList < timer, 0x20 > & freeList )
240 {
241  return freeList.allocate ( size );
242 }
243 
244 #ifdef CXX_PLACEMENT_DELETE
245 inline void timer::operator delete ( void * pCadaver,
246  tsFreeList < timer, 0x20 > & freeList )
247 {
248  freeList.release ( pCadaver );
249 }
250 #endif
251 
252 inline void * epicsTimerForC::operator new ( size_t size,
254 {
255  return freeList.allocate ( size );
256 }
257 
258 #ifdef CXX_PLACEMENT_DELETE
259 inline void epicsTimerForC::operator delete ( void * pCadaver,
261 {
262  freeList.release ( pCadaver );
263 }
264 #endif
265 
266 inline void * epicsTimerQueueActiveForC::operator new ( size_t size )
267 {
268  return ::operator new ( size );
269 }
270 
271 inline void epicsTimerQueueActiveForC::operator delete ( void * pCadaver )
272 {
273  ::operator delete ( pCadaver );
274 }
275 
276 #endif // epicsTimerPrivate_h
277 
void show(unsigned int level) const
Definition: timer.cpp:186
void destroy()
Definition: timer.cpp:47
pvd::StructureConstPtr type
Definition: memory.hpp:41
unsigned threadPriority() const
Definition: timerPrivate.h:233
epicsPlacementDeleteOperator((void *, tsFreeList< timer, 0x20 > &)) protecte ~timer)()
Definition: timerPrivate.h:46
void(* epicsTimerCallback)(void *pPrivate)
Definition: epicsTimer.h:134
double(* epicsTimerQueueNotifyQuantum)(void *pPrivate)
Definition: epicsTimer.h:153
epicsMutex mutex
Definition: pvAccess.cpp:71
expireInfo getExpireInfo() const
Definition: timer.cpp:174
char * allocate(unsigned int n)
Definition: antelope.c:230
epicsSingleton< timerQueueActiveMgr >::reference RefMgr
Definition: timerPrivate.h:132
timerQueue queue
Definition: timerPrivate.h:188
timerQueue & queue
Definition: timerPrivate.h:47
void cancel()
Definition: timer.cpp:135
epicsSingleton< timerQueueActiveMgr > timerQueueMgrEPICS
friend class timerQueue
Definition: timerPrivate.h:61
Compiler specific declarations.
bool sharingOK() const
Definition: timerPrivate.h:228
#define epicsThreadPriorityMin
Definition: epicsThread.h:72
void start(class epicsTimerNotify &, const epicsTime &)
Definition: timer.cpp:59
epicsSingleton< timerQueueActiveMgr >::reference RefThis
Definition: timerPrivate.h:165
void(* epicsTimerQueueNotifyReschedule)(void *pPrivate)
Definition: epicsTimer.h:152