generalTime short circuit current time
epicsTimeGetCurrent() is called frequently. Unless more than the default provider is registered, locking and going through the timeProvider list each time is a waste. Instead, short circuit to directly call the default time current time provider unless a another has been registered.
This commit is contained in:
@@ -78,6 +78,11 @@ static epicsThreadOnceId onceId = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
static const char * const tsfmt = "%Y-%m-%d %H:%M:%S.%09f";
|
||||
|
||||
/* defined in osiClockTime.c or osdTime.cpp */
|
||||
int osdTimeGetCurrent ( epicsTimeStamp *pDest );
|
||||
/* set if/when gtPvt.timeProviders contains more than the default osdTimeGetCurrent() */
|
||||
static int gtMoreThanDefault;
|
||||
|
||||
/* Implementation */
|
||||
|
||||
static void generalTime_InitOnce(void *dummy)
|
||||
@@ -103,6 +108,9 @@ int generalTimeGetExceptPriority(epicsTimeStamp *pDest, int *pPrio, int ignore)
|
||||
gtProvider *ptp;
|
||||
int status = S_time_noProvider;
|
||||
|
||||
if(!gtMoreThanDefault)
|
||||
return osdTimeGetCurrent(pDest);
|
||||
|
||||
generalTime_Init();
|
||||
|
||||
IFDEBUG(2)
|
||||
@@ -148,6 +156,9 @@ int epicsShareAPI epicsTimeGetCurrent(epicsTimeStamp *pDest)
|
||||
int status = S_time_noProvider;
|
||||
epicsTimeStamp ts;
|
||||
|
||||
if(!gtMoreThanDefault)
|
||||
return osdTimeGetCurrent(pDest);
|
||||
|
||||
generalTime_Init();
|
||||
|
||||
IFDEBUG(20)
|
||||
@@ -370,6 +381,11 @@ static void insertProvider(gtProvider *ptp, ELLLIST *plist, epicsMutexId lock)
|
||||
ellAdd(plist, &ptp->node);
|
||||
}
|
||||
|
||||
/* Check to see if we have more than just the OS default time source */
|
||||
if(plist==>Pvt.timeProviders && (ellCount(plist)!=1 || ptp->get.Time!=&osdTimeGetCurrent)) {
|
||||
gtMoreThanDefault = 1;
|
||||
}
|
||||
|
||||
epicsMutexUnlock(lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
static clock_serv_t host_clock;
|
||||
|
||||
extern "C" {
|
||||
static int osdTimeGetCurrent (epicsTimeStamp *pDest)
|
||||
int osdTimeGetCurrent (epicsTimeStamp *pDest)
|
||||
{
|
||||
mach_timespec_t mts;
|
||||
struct timespec ts;
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
|
||||
extern "C" void setThreadName ( DWORD dwThreadID, LPCSTR szThreadName );
|
||||
|
||||
static int osdTimeGetCurrent ( epicsTimeStamp *pDest );
|
||||
extern "C"
|
||||
int osdTimeGetCurrent ( epicsTimeStamp *pDest );
|
||||
|
||||
// for mingw
|
||||
#if !defined ( MAXLONGLONG )
|
||||
@@ -116,7 +117,7 @@ static int done = timeRegister();
|
||||
//
|
||||
// osdTimeGetCurrent ()
|
||||
//
|
||||
static int osdTimeGetCurrent ( epicsTimeStamp *pDest )
|
||||
int osdTimeGetCurrent ( epicsTimeStamp *pDest )
|
||||
{
|
||||
assert ( pCurrentTime );
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
LAST_RESORT_PRIORITY, osdTimeGetCurrent)
|
||||
|
||||
extern "C" {
|
||||
static int osdTimeGetCurrent (epicsTimeStamp *pDest)
|
||||
int osdTimeGetCurrent (epicsTimeStamp *pDest)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
@@ -48,7 +48,7 @@ static epicsThreadOnceId onceId = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
/* Forward references */
|
||||
|
||||
static int ClockTimeGetCurrent(epicsTimeStamp *pDest);
|
||||
int osdTimeGetCurrent(epicsTimeStamp *pDest);
|
||||
|
||||
#if defined(vxWorks) || defined(__rtems__)
|
||||
static void ClockTimeSync(void *dummy);
|
||||
@@ -89,7 +89,7 @@ static void ClockTime_InitOnce(void *pfirst)
|
||||
|
||||
/* Register as a time provider */
|
||||
generalTimeRegisterCurrentProvider("OS Clock", LAST_RESORT_PRIORITY,
|
||||
ClockTimeGetCurrent);
|
||||
osdTimeGetCurrent);
|
||||
}
|
||||
|
||||
void ClockTime_Init(int synchronize)
|
||||
@@ -125,7 +125,7 @@ void ClockTime_Init(int synchronize)
|
||||
else {
|
||||
/* No synchronization thread */
|
||||
if (firstTime)
|
||||
ClockTimeGetCurrent(&ClockTimePvt.startTime);
|
||||
osdTimeGetCurrent(&ClockTimePvt.startTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ static void ClockTimeSync(void *dummy)
|
||||
|
||||
/* Time Provider Routine */
|
||||
|
||||
static int ClockTimeGetCurrent(epicsTimeStamp *pDest)
|
||||
int osdTimeGetCurrent(epicsTimeStamp *pDest)
|
||||
{
|
||||
struct timespec clockNow;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user