22 # pragma warning ( push ) 23 # pragma warning ( disable:4660 ) 29 # pragma warning ( pop ) 34 epicsTimerQueueActive::~epicsTimerQueueActive () {}
40 return pMgr->allocate ( pMgr, okToShare, threadPriority );
45 bool okToShareIn,
unsigned priority ) :
46 _refMgr ( refMgr ), queue ( *this ), thread ( *this,
"timerQueue",
49 exitFlag ( 0 ), terminateFlag (
false )
55 this->thread.start ();
60 this->terminateFlag =
true;
61 this->rescheduleEvent.signal ();
63 this->exitEvent.wait ( 1.0 );
66 this->exitEvent.signal ();
69 void timerQueueActive :: _printLastChanceExceptionMessage (
70 const char * pExceptionTypeName,
71 const char * pExceptionContext )
75 epicsTime cur = epicsTime :: getCurrent ();
76 cur.strftime ( date,
sizeof ( date ),
"%a %b %d %Y %H:%M:%S.%f");
79 strcpy ( date,
"<UKN DATE>" );
82 "timerQueueActive: Unexpected C++ exception \"%s\" with type \"%s\" " 83 "while processing timer queue, at %s\n",
84 pExceptionContext, pExceptionTypeName, date );
88 void timerQueueActive :: run ()
90 epics::atomic::set(this->exitFlag, 0);
91 while ( ! this->terminateFlag ) {
93 double delay = this->queue.
process ( epicsTime::getCurrent() );
94 debugPrintf ( (
"timer thread sleeping for %g sec (max)\n", delay ) );
95 this->rescheduleEvent.wait ( delay );
97 catch ( std :: exception & except ) {
98 _printLastChanceExceptionMessage (
99 typeid ( except ).name (), except.what () );
103 _printLastChanceExceptionMessage (
104 "catch ( ... )",
"Non-standard C++ exception" );
108 epics::atomic::set(this->exitFlag, 1);
109 this->exitEvent.signal ();
122 void timerQueueActive::reschedule ()
124 this->rescheduleEvent.signal ();
127 double timerQueueActive::quantum ()
129 return this->sleepQuantum;
134 printf (
"EPICS threaded timer queue at %p\n",
135 static_cast <const void *> (
this ) );
139 this->thread.show ( 1u );
140 this->queue.
show ( level - 1u );
141 printf (
"reschedule event\n" );
142 this->rescheduleEvent.show ( level - 1u );
143 printf (
"exit event\n" );
144 this->exitEvent.show ( level - 1u );
145 printf (
"exitFlag = %c, terminateFlag = %c\n",
147 this->terminateFlag ?
'T' :
'F' );
151 epicsTimerQueue & timerQueueActive::getEpicsTimerQueue ()
153 return static_cast < epicsTimerQueue &> ( * this );
void show(unsigned int level) const
LIBCOM_API double epicsStdCall epicsThreadSleepQuantum(void)
Query a value approximating the OS timer/scheduler resolution.
epicsTimer & createTimer()
epicsSingleton< timerQueueActiveMgr > timerQueueMgrEPICS
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
epicsTimerForC & createTimerForC(epicsTimerCallback pCallback, void *pArg)
void(* epicsTimerCallback)(void *pPrivate)
char * allocate(unsigned int n)
void show(unsigned int level) const
epicsSingleton< timerQueueActiveMgr >::reference RefMgr
int errlogPrintf(const char *pFormat,...)
void date(const char *format)
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
epicsTimer & createTimer()
#define debugPrintf(argsInParen)
epicsTimerForC & createTimerForC(epicsTimerCallback pCallback, void *pArg)
timerQueueActive(RefMgr &, bool okToShare, unsigned priority)
double process(const epicsTime ¤tTime)