This is Unofficial EPICS BASE Doxygen Site
epicsTimer.cpp
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 #include <string>
16 #include <stdexcept>
17 
18 #include "epicsMath.h"
19 #include "epicsTimer.h"
20 #include "epicsGuard.h"
21 #include "timerPrivate.h"
22 
23 #ifdef _MSC_VER
24 # pragma warning ( push )
25 # pragma warning ( disable:4660 )
26 #endif
27 
28 #ifdef _MSC_VER
29 # pragma warning ( pop )
30 #endif
31 
33 
34 epicsTimer::~epicsTimer () {}
35 
36 epicsTimerQueueNotify::~epicsTimerQueueNotify () {}
37 
38 epicsTimerNotify::~epicsTimerNotify () {}
39 
40 void epicsTimerNotify::show ( unsigned /* level */ ) const {}
41 
42 epicsTimerForC::epicsTimerForC ( timerQueue &queue, epicsTimerCallback pCBIn, void *pPrivateIn ) :
43  timer ( queue ), pCallBack ( pCBIn ), pPrivate ( pPrivateIn )
44 {
45 }
46 
48 {
49 }
50 
52 {
53  timerQueue & queueTmp = this->queue;
54  this->~epicsTimerForC ();
55  queueTmp.timerForCFreeList.release ( this );
56 }
57 
58 epicsTimerNotify::expireStatus epicsTimerForC::expire ( const epicsTime & )
59 {
60  ( *this->pCallBack ) ( this->pPrivate );
61  return noRestart;
62 }
63 
66  bool okToShare, unsigned priority ) :
67  timerQueueActive ( refMgr, okToShare, priority )
68 {
70 }
71 
73 {
74 }
75 
77 {
78  _refMgr->release ( *this );
79 }
80 
82  epicsTimerQueueNotifyReschedule pRescheduleCallbackIn,
83  epicsTimerQueueNotifyQuantum pSleepQuantumCallbackIn,
84  void * pPrivateIn ) :
85  timerQueuePassive ( * static_cast < epicsTimerQueueNotify * > ( this ) ),
86  pRescheduleCallback ( pRescheduleCallbackIn ),
87  pSleepQuantumCallback ( pSleepQuantumCallbackIn ),
88  pPrivate ( pPrivateIn )
89 {
90 }
91 
93 {
94 }
95 
96 void epicsTimerQueuePassiveForC::reschedule ()
97 {
98  (*this->pRescheduleCallback) ( this->pPrivate );
99 }
100 
101 double epicsTimerQueuePassiveForC::quantum ()
102 {
103  return (*this->pSleepQuantumCallback) ( this->pPrivate );
104 }
105 
107 {
108  delete this;
109 }
110 
111 LIBCOM_API epicsTimerNotify::expireStatus::expireStatus ( restart_t restart ) :
112  delay ( - DBL_MAX )
113 {
114  if ( restart != noRestart ) {
115  throw std::logic_error
116  ( "timer restart was requested without specifying a delay?" );
117  }
118 }
119 
120 LIBCOM_API epicsTimerNotify::expireStatus::expireStatus
121  ( restart_t restartIn, const double & expireDelaySec ) :
122  delay ( expireDelaySec )
123 {
124  if ( restartIn != epicsTimerNotify::restart ) {
125  throw std::logic_error
126  ( "no timer restart was requested, but a delay was specified?" );
127  }
128  if ( this->delay < 0.0 || !finite(this->delay) ) {
129  throw std::logic_error
130  ( "timer restart was requested, but a negative delay was specified?" );
131  }
132 }
133 
134 LIBCOM_API bool epicsTimerNotify::expireStatus::restart () const
135 {
136  return this->delay >= 0.0 && finite(this->delay);
137 }
138 
139 LIBCOM_API double epicsTimerNotify::expireStatus::expirationDelay () const
140 {
141  if ( this->delay < 0.0 || !finite(this->delay) ) {
142  throw std::logic_error
143  ( "no timer restart was requested, but you are asking for a restart delay?" );
144  }
145  return this->delay;
146 }
147 
148 extern "C" epicsTimerQueuePassiveId epicsStdCall
150  epicsTimerQueueNotifyReschedule pRescheduleCallbackIn,
151  epicsTimerQueueNotifyQuantum pSleepQuantumCallbackIn,
152  void * pPrivateIn )
153 {
154  try {
155  return new epicsTimerQueuePassiveForC (
156  pRescheduleCallbackIn,
157  pSleepQuantumCallbackIn,
158  pPrivateIn );
159  }
160  catch ( ... ) {
161  return 0;
162  }
163 }
164 
165 extern "C" void epicsStdCall
167 {
168  pQueue->destroy ();
169 }
170 
171 extern "C" double epicsStdCall
173 {
174  try {
175  return pQueue->process ( epicsTime::getCurrent() );
176  }
177  catch ( ... ) {
178  return 1.0;
179  }
180 }
181 
183  epicsTimerQueuePassiveId pQueue, epicsTimerCallback pCallback, void *pArg )
184 {
185  try {
186  return & pQueue->createTimerForC ( pCallback, pArg );
187  }
188  catch ( ... ) {
189  return 0;
190  }
191 }
192 
193 extern "C" LIBCOM_API void epicsStdCall epicsTimerQueuePassiveDestroyTimer (
194  epicsTimerQueuePassiveId /* pQueue */, epicsTimerId pTmr )
195 {
196  pTmr->destroy ();
197 }
198 
199 extern "C" void epicsStdCall epicsTimerQueuePassiveShow (
200  epicsTimerQueuePassiveId pQueue, unsigned int level )
201 {
202  pQueue->show ( level );
203 }
204 
205 extern "C" epicsTimerQueueId epicsStdCall
206  epicsTimerQueueAllocate ( int okToShare, unsigned int threadPriority )
207 {
208  try {
209  epicsSingleton < timerQueueActiveMgr > :: reference ref =
212  ref->allocate ( ref, okToShare ? true : false, threadPriority );
213  return &tmr;
214  }
215  catch ( ... ) {
216  return 0;
217  }
218 }
219 
220 extern "C" void epicsStdCall epicsTimerQueueRelease ( epicsTimerQueueId pQueue )
221 {
222  pQueue->release ();
223 }
224 
225 extern "C" epicsTimerId epicsStdCall epicsTimerQueueCreateTimer (
226  epicsTimerQueueId pQueue, epicsTimerCallback pCallback, void *pArg )
227 {
228  try {
229  return & pQueue->createTimerForC ( pCallback, pArg );
230  }
231  catch ( ... ) {
232  return 0;
233  }
234 }
235 
236 extern "C" void epicsStdCall epicsTimerQueueShow (
237  epicsTimerQueueId pQueue, unsigned int level )
238 {
239  pQueue->show ( level );
240 }
241 
242 extern "C" void epicsStdCall epicsTimerQueueDestroyTimer (
243  epicsTimerQueueId /* pQueue */, epicsTimerId pTmr )
244 {
245  pTmr->destroy ();
246 }
247 
248 extern "C" void epicsStdCall epicsTimerStartTime (
249  epicsTimerId pTmr, const epicsTimeStamp *pTime )
250 {
251  pTmr->start ( *pTmr, *pTime );
252 }
253 
254 extern "C" void epicsStdCall epicsTimerStartDelay (
255  epicsTimerId pTmr, double delaySeconds )
256 {
257  pTmr->start ( *pTmr, delaySeconds );
258 }
259 
260 extern "C" void epicsStdCall epicsTimerCancel ( epicsTimerId pTmr )
261 {
262  pTmr->cancel ();
263 }
264 
265 extern "C" double epicsStdCall epicsTimerGetExpireDelay ( epicsTimerId pTmr )
266 {
267  return pTmr->getExpireDelay ();
268 }
269 
270 extern "C" void epicsStdCall epicsTimerShow (
271  epicsTimerId pTmr, unsigned int level )
272 {
273  pTmr->timer::show ( level );
274 }
275 
double epicsStdCall epicsTimerGetExpireDelay(epicsTimerId pTmr)
Definition: epicsTimer.cpp:265
epicsTimerId epicsStdCall epicsTimerQueueCreateTimer(epicsTimerQueueId pQueue, epicsTimerCallback pCallback, void *pArg)
Definition: epicsTimer.cpp:225
LIBCOM_API void epicsStdCall epicsTimerQueuePassiveDestroyTimer(epicsTimerQueuePassiveId, epicsTimerId pTmr)
Definition: epicsTimer.cpp:193
expireStatus expire(const epicsTime &currentTime)
Definition: epicsTimer.cpp:58
epicsTimerQueuePassiveId epicsStdCall epicsTimerQueuePassiveCreate(epicsTimerQueueNotifyReschedule pRescheduleCallbackIn, epicsTimerQueueNotifyQuantum pSleepQuantumCallbackIn, void *pPrivateIn)
Definition: epicsTimer.cpp:149
epicsTimerId epicsStdCall epicsTimerQueuePassiveCreateTimer(epicsTimerQueuePassiveId pQueue, epicsTimerCallback pCallback, void *pArg)
Definition: epicsTimer.cpp:182
reference getReference()
void epicsStdCall epicsTimerCancel(epicsTimerId pTmr)
Definition: epicsTimer.cpp:260
void show(unsigned int level) const
epicsTimerQueueId epicsStdCall epicsTimerQueueAllocate(int okToShare, unsigned int threadPriority)
Definition: epicsTimer.cpp:206
void epicsStdCall epicsTimerQueueRelease(epicsTimerQueueId pQueue)
Definition: epicsTimer.cpp:220
void(* epicsTimerCallback)(void *pPrivate)
Definition: epicsTimer.h:134
epicsTimerQueuePassiveForC(epicsTimerQueueNotifyReschedule, epicsTimerQueueNotifyQuantum, void *pPrivate)
Definition: epicsTimer.cpp:81
void epicsStdCall epicsTimerStartTime(epicsTimerId pTmr, const epicsTimeStamp *pTime)
Definition: epicsTimer.cpp:248
double(* epicsTimerQueueNotifyQuantum)(void *pPrivate)
Definition: epicsTimer.h:153
virtual ~epicsTimerQueueActiveForC()
Definition: epicsTimer.cpp:72
epicsTimerQueueActiveForC(RefMgr &, bool okToShare, unsigned priority)
Definition: epicsTimer.cpp:65
void show(unsigned int level) const
epicsSingleton< timerQueueActiveMgr >::reference RefMgr
Definition: timerPrivate.h:132
double epicsStdCall epicsTimerQueuePassiveProcess(epicsTimerQueuePassiveId pQueue)
Definition: epicsTimer.cpp:172
timerQueue & queue
Definition: timerPrivate.h:47
epicsTimerForC & createTimerForC(epicsTimerCallback pCallback, void *pArg)
void epicsStdCall epicsTimerQueuePassiveShow(epicsTimerQueuePassiveId pQueue, unsigned int level)
Definition: epicsTimer.cpp:199
void epicsStdCall epicsTimerQueuePassiveDestroy(epicsTimerQueuePassiveId pQueue)
Definition: epicsTimer.cpp:166
void cancel()
Definition: timer.cpp:135
void epicsStdCall epicsTimerShow(epicsTimerId pTmr, unsigned int level)
Definition: epicsTimer.cpp:270
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
double process(const epicsTime &currentTime)
epicsSingleton< timerQueueActiveMgr > timerQueueMgrEPICS
void epicsStdCall epicsTimerQueueDestroyTimer(epicsTimerQueueId, epicsTimerId pTmr)
Definition: epicsTimer.cpp:242
void release(void *p)
Definition: tsFreeList.h:176
void epicsStdCall epicsTimerStartDelay(epicsTimerId pTmr, double delaySeconds)
Definition: epicsTimer.cpp:254
epicsPlacementDeleteOperator((void *, tsFreeList< epicsTimerForC, 0x20 > &)) private void pPrivate)
Definition: timerPrivate.h:71
epicsTimerForC(timerQueue &, epicsTimerCallback, void *pPrivateIn)
Definition: epicsTimer.cpp:42
#define finite(x)
Definition: epicsMath.h:16
epicsTimerForC & createTimerForC(epicsTimerCallback pCallback, void *pArg)
void epicsStdCall epicsTimerQueueShow(epicsTimerQueueId pQueue, unsigned int level)
Definition: epicsTimer.cpp:236
void start(class epicsTimerNotify &, const epicsTime &)
Definition: timer.cpp:59
void(* epicsTimerQueueNotifyReschedule)(void *pPrivate)
Definition: epicsTimer.h:152