Expanded tabs, replaced malloc() + bzero() with calloc().
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/***************************************************************************
|
||||
* File: epicsGeneralTime.c
|
||||
* Author: Sheng Peng
|
||||
* Institution: Oak Ridge National Laboratory / SNS Project
|
||||
* Date: 07/2004
|
||||
* Version: 1.3
|
||||
* File: epicsGeneralTime.c
|
||||
* Author: Sheng Peng
|
||||
* Institution: Oak Ridge National Laboratory / SNS Project
|
||||
* Date: 07/2004
|
||||
* Version: 1.3
|
||||
*
|
||||
* EPICS general timestamp support
|
||||
* integration into EPICS Base by Peter Denison, Diamond Light Source
|
||||
@@ -69,10 +69,10 @@ typedef struct generalTimePvt
|
||||
unsigned int ErrorCounts;
|
||||
} generalTimePvt;
|
||||
|
||||
int generalTimeGetCurrent(epicsTimeStamp *pDest);
|
||||
static int generalTimeGetCurrentPriority(epicsTimeStamp *pDest, int * pPriority);
|
||||
int generalTimeGetCurrent(epicsTimeStamp *pDest);
|
||||
static int generalTimeGetCurrentPriority(epicsTimeStamp *pDest, int * pPriority);
|
||||
int generalTimeGetEvent(epicsTimeStamp *pDest,int eventNumber);
|
||||
static int generalTimeGetEventPriority(epicsTimeStamp *pDest,int eventNumber, int * pPriority);
|
||||
static int generalTimeGetEventPriority(epicsTimeStamp *pDest,int eventNumber, int * pPriority);
|
||||
|
||||
long generalTimeReport(int level);
|
||||
|
||||
@@ -84,16 +84,16 @@ int GENERALTIME_DEBUG=0;
|
||||
/* implementation */
|
||||
void generalTime_InitOnce(void)
|
||||
{
|
||||
pgeneralTimePvt = (generalTimePvt *)callocMustSucceed(1,sizeof(generalTimePvt),"generalTime_Init");
|
||||
pgeneralTimePvt = (generalTimePvt *)callocMustSucceed(1,sizeof(generalTimePvt),"generalTime_Init");
|
||||
|
||||
ellInit(&(pgeneralTimePvt->tcp_list));
|
||||
pgeneralTimePvt->tcp_list_sem = epicsMutexMustCreate();
|
||||
ellInit(&(pgeneralTimePvt->tcp_list));
|
||||
pgeneralTimePvt->tcp_list_sem = epicsMutexMustCreate();
|
||||
|
||||
ellInit(&(pgeneralTimePvt->tep_list));
|
||||
pgeneralTimePvt->tep_list_sem = epicsMutexMustCreate();
|
||||
ellInit(&(pgeneralTimePvt->tep_list));
|
||||
pgeneralTimePvt->tep_list_sem = epicsMutexMustCreate();
|
||||
|
||||
/* Initialise the "last-resort" provider on a per-architecture basis */
|
||||
osdTimeInit();
|
||||
/* Initialise the "last-resort" provider on a per-architecture basis */
|
||||
osdTimeInit();
|
||||
}
|
||||
|
||||
void generalTime_Init(void)
|
||||
@@ -106,130 +106,130 @@ void generalTime_Init(void)
|
||||
|
||||
int epicsTimeGetCurrent(epicsTimeStamp *pDest)
|
||||
{
|
||||
int priority;
|
||||
return(generalTimeGetCurrentPriority(pDest, &priority));
|
||||
int priority;
|
||||
return(generalTimeGetCurrentPriority(pDest, &priority));
|
||||
}
|
||||
|
||||
static int generalTimeGetCurrentPriority(epicsTimeStamp *pDest, int * pPriority)
|
||||
{
|
||||
return(generalTimeGetExceptPriority(pDest, pPriority, 0)); /* no tcp is excluded */
|
||||
return(generalTimeGetExceptPriority(pDest, pPriority, 0)); /* no tcp is excluded */
|
||||
|
||||
}
|
||||
|
||||
int generalTimeGetExceptPriority(epicsTimeStamp *pDest, int * pPriority, int except_tcp)
|
||||
int generalTimeGetExceptPriority(epicsTimeStamp *pDest, int * pPriority, int except_tcp)
|
||||
{
|
||||
int key;
|
||||
TIME_CURRENT_PROVIDER * ptcp;
|
||||
int status = epicsTimeERROR;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
int key;
|
||||
TIME_CURRENT_PROVIDER * ptcp;
|
||||
int status = epicsTimeERROR;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
for(ptcp=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcp; ptcp=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcp))
|
||||
{/* when we register providers, we sort them by priority */
|
||||
/* Allow providers to ask for time not including their own */
|
||||
if (ptcp->tcp_priority == except_tcp) {
|
||||
continue;
|
||||
}
|
||||
if(ptcp->tcp_getCurrent)
|
||||
status=(*(ptcp->tcp_getCurrent))(pDest);
|
||||
if(status!=epicsTimeERROR)
|
||||
{/* we can check if time monotonic here */
|
||||
if (epicsTimeGreaterThanEqual(pDest, &(pgeneralTimePvt->lastKnownTimeCurrent))) {
|
||||
pgeneralTimePvt->lastKnownTimeCurrent=*pDest;
|
||||
pgeneralTimePvt->pLastKnownBestTcp=ptcp;
|
||||
*pPriority = ptcp->tcp_priority;
|
||||
} else {
|
||||
epicsTimeStamp orig = *pDest;
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeCurrent;
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
for(ptcp=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcp; ptcp=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcp))
|
||||
{/* when we register providers, we sort them by priority */
|
||||
/* Allow providers to ask for time not including their own */
|
||||
if (ptcp->tcp_priority == except_tcp) {
|
||||
continue;
|
||||
}
|
||||
if(ptcp->tcp_getCurrent)
|
||||
status=(*(ptcp->tcp_getCurrent))(pDest);
|
||||
if(status!=epicsTimeERROR)
|
||||
{/* we can check if time monotonic here */
|
||||
if (epicsTimeGreaterThanEqual(pDest, &(pgeneralTimePvt->lastKnownTimeCurrent))) {
|
||||
pgeneralTimePvt->lastKnownTimeCurrent=*pDest;
|
||||
pgeneralTimePvt->pLastKnownBestTcp=ptcp;
|
||||
*pPriority = ptcp->tcp_priority;
|
||||
} else {
|
||||
epicsTimeStamp orig = *pDest;
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeCurrent;
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
sprintf(logBuffer, "TCP provider \"%s\" provides backwards time!\nnew = %us, %uns, last = %us, %uns (%s)\n",
|
||||
ptcp->tp_desc,orig.secPastEpoch,orig.nsec,pDest->secPastEpoch,pDest->nsec,
|
||||
pgeneralTimePvt->pLastKnownBestTcp->tp_desc);
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
*pPriority = pgeneralTimePvt->pLastKnownBestTcp->tcp_priority;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(status==epicsTimeERROR)
|
||||
pgeneralTimePvt->pLastKnownBestTcp=NULL;
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
*pPriority = pgeneralTimePvt->pLastKnownBestTcp->tcp_priority;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(status==epicsTimeERROR)
|
||||
pgeneralTimePvt->pLastKnownBestTcp=NULL;
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
int epicsTimeGetEvent(epicsTimeStamp *pDest,int eventNumber)
|
||||
{
|
||||
int priority;
|
||||
if (eventNumber == epicsTimeEventCurrentTime) {
|
||||
return generalTimeGetCurrentPriority(pDest, &priority);
|
||||
} else {
|
||||
return(generalTimeGetEventPriority(pDest, eventNumber, &priority));
|
||||
}
|
||||
int priority;
|
||||
if (eventNumber == epicsTimeEventCurrentTime) {
|
||||
return generalTimeGetCurrentPriority(pDest, &priority);
|
||||
} else {
|
||||
return(generalTimeGetEventPriority(pDest, eventNumber, &priority));
|
||||
}
|
||||
}
|
||||
|
||||
static int generalTimeGetEventPriority(epicsTimeStamp *pDest,int eventNumber, int * pPriority)
|
||||
{
|
||||
int key;
|
||||
TIME_EVENT_PROVIDER * ptep;
|
||||
int status = epicsTimeERROR;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
int key;
|
||||
TIME_EVENT_PROVIDER * ptep;
|
||||
int status = epicsTimeERROR;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
for(ptep=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptep; ptep=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptep))
|
||||
{/* when we register provider, we sort them by priority */
|
||||
if(ptep->tep_getEvent)
|
||||
status=(*(ptep->tep_getEvent))(pDest,eventNumber);
|
||||
if(status!=epicsTimeERROR)
|
||||
{/* we can check if time monotonic here */
|
||||
pgeneralTimePvt->pLastKnownBestTep=ptep;
|
||||
*pPriority = ptep->tep_priority;
|
||||
if(eventNumber>=0 && eventNumber<NUM_OF_EVENTS)
|
||||
{
|
||||
if (epicsTimeGreaterThanEqual(pDest,&(pgeneralTimePvt->lastKnownTimeEvent[eventNumber]))) {
|
||||
pgeneralTimePvt->lastKnownTimeEvent[eventNumber]=*pDest;
|
||||
} else {
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeEvent[eventNumber];
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
for(ptep=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptep; ptep=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptep))
|
||||
{/* when we register provider, we sort them by priority */
|
||||
if(ptep->tep_getEvent)
|
||||
status=(*(ptep->tep_getEvent))(pDest,eventNumber);
|
||||
if(status!=epicsTimeERROR)
|
||||
{/* we can check if time monotonic here */
|
||||
pgeneralTimePvt->pLastKnownBestTep=ptep;
|
||||
*pPriority = ptep->tep_priority;
|
||||
if(eventNumber>=0 && eventNumber<NUM_OF_EVENTS)
|
||||
{
|
||||
if (epicsTimeGreaterThanEqual(pDest,&(pgeneralTimePvt->lastKnownTimeEvent[eventNumber]))) {
|
||||
pgeneralTimePvt->lastKnownTimeEvent[eventNumber]=*pDest;
|
||||
} else {
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeEvent[eventNumber];
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
sprintf(logBuffer, "TEP provider \"%s\" provides backwards time on Event %d!\n", ptep->tp_desc, eventNumber);
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventNumber==epicsTimeEventBestTime)
|
||||
{
|
||||
if (epicsTimeGreaterThanEqual(pDest,&(pgeneralTimePvt->lastKnownTimeEventBestTime))) {
|
||||
pgeneralTimePvt->lastKnownTimeEventBestTime=*pDest;
|
||||
} else {
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeEventBestTime;
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventNumber==epicsTimeEventBestTime)
|
||||
{
|
||||
if (epicsTimeGreaterThanEqual(pDest,&(pgeneralTimePvt->lastKnownTimeEventBestTime))) {
|
||||
pgeneralTimePvt->lastKnownTimeEventBestTime=*pDest;
|
||||
} else {
|
||||
*pDest=pgeneralTimePvt->lastKnownTimeEventBestTime;
|
||||
key = epicsInterruptLock(); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
pgeneralTimePvt->ErrorCounts++;
|
||||
epicsInterruptUnlock(key); /* OSI has no taskLock, but if we lock interrupt, it is good enough */
|
||||
if(GENERALTIME_DEBUG) {
|
||||
sprintf(logBuffer, "TEP provider \"%s\" provides backwards time on Event BestTime!\n", ptep->tp_desc);
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(status==epicsTimeERROR)
|
||||
pgeneralTimePvt->pLastKnownBestTep=NULL;
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
epicsInterruptContextMessage(logBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(status==epicsTimeERROR)
|
||||
pgeneralTimePvt->pLastKnownBestTep=NULL;
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -240,80 +240,80 @@ static int generalTimeGetEventPriority(epicsTimeStamp *pDest,int eventNumber
|
||||
* I think it's simpler to leave the duplication there.
|
||||
*/
|
||||
|
||||
int generalTimeEventTpRegister(const char *desc, int priority, pepicsTimeGetEvent getEvent)
|
||||
int generalTimeEventTpRegister(const char *desc, int priority, pepicsTimeGetEvent getEvent)
|
||||
{
|
||||
TIME_EVENT_PROVIDER * ptep, * ptepref;
|
||||
TIME_EVENT_PROVIDER * ptep, * ptepref;
|
||||
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
|
||||
ptep=(TIME_EVENT_PROVIDER *)malloc(sizeof(TIME_EVENT_PROVIDER));
|
||||
ptep=(TIME_EVENT_PROVIDER *)malloc(sizeof(TIME_EVENT_PROVIDER));
|
||||
|
||||
if(ptep==NULL) {
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
if(ptep==NULL) {
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
|
||||
strncpy(ptep->tp_desc,desc,TP_DESC_LEN-1);
|
||||
ptep->tp_desc[TP_DESC_LEN-1]='\0';
|
||||
ptep->tep_priority=priority;
|
||||
ptep->tep_getEvent=getEvent;
|
||||
strncpy(ptep->tp_desc,desc,TP_DESC_LEN-1);
|
||||
ptep->tp_desc[TP_DESC_LEN-1]='\0';
|
||||
ptep->tep_priority=priority;
|
||||
ptep->tep_getEvent=getEvent;
|
||||
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
for(ptepref=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptepref; ptepref=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptepref))
|
||||
{
|
||||
if(ptepref->tep_priority > ptep->tep_priority) break;
|
||||
}
|
||||
if(ptepref)
|
||||
{/* found a ref whose priority is just bigger than the new one */
|
||||
ptepref=(TIME_EVENT_PROVIDER *)ellPrevious((ELLNODE *)ptepref);
|
||||
ellInsert( &(pgeneralTimePvt->tep_list), (ELLNODE *)ptepref, (ELLNODE *)ptep );
|
||||
}
|
||||
else
|
||||
{/* either list is empty or no one have bigger(lower) priority, put on tail */
|
||||
ellAdd( &(pgeneralTimePvt->tep_list), (ELLNODE *)ptep );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
for(ptepref=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptepref; ptepref=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptepref))
|
||||
{
|
||||
if(ptepref->tep_priority > ptep->tep_priority) break;
|
||||
}
|
||||
if(ptepref)
|
||||
{/* found a ref whose priority is just bigger than the new one */
|
||||
ptepref=(TIME_EVENT_PROVIDER *)ellPrevious((ELLNODE *)ptepref);
|
||||
ellInsert( &(pgeneralTimePvt->tep_list), (ELLNODE *)ptepref, (ELLNODE *)ptep );
|
||||
}
|
||||
else
|
||||
{/* either list is empty or no one have bigger(lower) priority, put on tail */
|
||||
ellAdd( &(pgeneralTimePvt->tep_list), (ELLNODE *)ptep );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
|
||||
return epicsTimeOK;
|
||||
return epicsTimeOK;
|
||||
}
|
||||
|
||||
int generalTimeCurrentTpRegister(const char *desc, int priority, pepicsTimeGetCurrent getCurrent)
|
||||
int generalTimeCurrentTpRegister(const char *desc, int priority, pepicsTimeGetCurrent getCurrent)
|
||||
{
|
||||
TIME_CURRENT_PROVIDER * ptcp, * ptcpref;
|
||||
TIME_CURRENT_PROVIDER * ptcp, * ptcpref;
|
||||
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
|
||||
ptcp=(TIME_CURRENT_PROVIDER *)malloc(sizeof(TIME_CURRENT_PROVIDER));
|
||||
ptcp=(TIME_CURRENT_PROVIDER *)malloc(sizeof(TIME_CURRENT_PROVIDER));
|
||||
|
||||
if(ptcp==NULL) {
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
if(ptcp==NULL) {
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
|
||||
strncpy(ptcp->tp_desc,desc,TP_DESC_LEN-1);
|
||||
ptcp->tp_desc[TP_DESC_LEN-1]='\0';
|
||||
ptcp->tcp_priority=priority;
|
||||
ptcp->tcp_getCurrent=getCurrent;
|
||||
strncpy(ptcp->tp_desc,desc,TP_DESC_LEN-1);
|
||||
ptcp->tp_desc[TP_DESC_LEN-1]='\0';
|
||||
ptcp->tcp_priority=priority;
|
||||
ptcp->tcp_getCurrent=getCurrent;
|
||||
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
for(ptcpref=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcpref; ptcpref=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcpref))
|
||||
{
|
||||
if(ptcpref->tcp_priority > ptcp->tcp_priority) break;
|
||||
}
|
||||
if(ptcpref)
|
||||
{/* found a ref whose priority is just bigger than the new one */
|
||||
ptcpref=(TIME_CURRENT_PROVIDER *)ellPrevious((ELLNODE *)ptcpref);
|
||||
ellInsert( &(pgeneralTimePvt->tcp_list), (ELLNODE *)ptcpref, (ELLNODE *)ptcp );
|
||||
}
|
||||
else
|
||||
{/* either list is empty or no one have bigger(lower) priority, put on tail */
|
||||
ellAdd( &(pgeneralTimePvt->tcp_list), (ELLNODE *)ptcp );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem);
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
for(ptcpref=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcpref; ptcpref=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcpref))
|
||||
{
|
||||
if(ptcpref->tcp_priority > ptcp->tcp_priority) break;
|
||||
}
|
||||
if(ptcpref)
|
||||
{/* found a ref whose priority is just bigger than the new one */
|
||||
ptcpref=(TIME_CURRENT_PROVIDER *)ellPrevious((ELLNODE *)ptcpref);
|
||||
ellInsert( &(pgeneralTimePvt->tcp_list), (ELLNODE *)ptcpref, (ELLNODE *)ptcp );
|
||||
}
|
||||
else
|
||||
{/* either list is empty or no one have bigger(lower) priority, put on tail */
|
||||
ellAdd( &(pgeneralTimePvt->tcp_list), (ELLNODE *)ptcp );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem);
|
||||
|
||||
return epicsTimeOK;
|
||||
return epicsTimeOK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -330,135 +330,134 @@ int generalTimeCurrentTpRegister(const char *desc, int priority, pepicsTimeGetC
|
||||
*/
|
||||
static int lastResortGetEvent(epicsTimeStamp *timeStamp, int eventNumber)
|
||||
{
|
||||
return epicsTimeGetCurrent(timeStamp);
|
||||
return epicsTimeGetCurrent(timeStamp);
|
||||
}
|
||||
|
||||
int lastResortEventProviderInstall(void)
|
||||
{
|
||||
return generalTimeEventTpRegister("Last Resort Event", LAST_RESORT_PRIORITY, lastResortGetEvent);
|
||||
return generalTimeEventTpRegister("Last Resort Event", LAST_RESORT_PRIORITY, lastResortGetEvent);
|
||||
}
|
||||
|
||||
epicsTimerId generalTimeCreateSyncTimer(epicsTimerCallback cb, void* param)
|
||||
{
|
||||
if (!pgeneralTimePvt->sync_queue) {
|
||||
pgeneralTimePvt->sync_queue = epicsTimerQueueAllocate(0, epicsThreadPriorityHigh);
|
||||
}
|
||||
return epicsTimerQueueCreateTimer(pgeneralTimePvt->sync_queue, cb, param);
|
||||
if (!pgeneralTimePvt->sync_queue) {
|
||||
pgeneralTimePvt->sync_queue = epicsTimerQueueAllocate(0, epicsThreadPriorityHigh);
|
||||
}
|
||||
return epicsTimerQueueCreateTimer(pgeneralTimePvt->sync_queue, cb, param);
|
||||
}
|
||||
|
||||
long generalTimeReport(int level)
|
||||
{
|
||||
TIME_CURRENT_PROVIDER * ptcp;
|
||||
TIME_EVENT_PROVIDER * ptep;
|
||||
TIME_CURRENT_PROVIDER * ptcp;
|
||||
TIME_EVENT_PROVIDER * ptep;
|
||||
|
||||
int status;
|
||||
epicsTimeStamp tempTS;
|
||||
char tempTSText[40];
|
||||
int status;
|
||||
epicsTimeStamp tempTS;
|
||||
char tempTSText[40];
|
||||
|
||||
int items; /* how many provider we have */
|
||||
char * ptempText; /* logMsg passed pointer instead of strcpy, so we have to keep a local screen copy then printf */
|
||||
int tempTextOffset;
|
||||
int items; /* how many provider we have */
|
||||
char * ptempText; /* logMsg passed pointer instead of strcpy, so we have to keep a local screen copy then printf */
|
||||
int tempTextOffset;
|
||||
|
||||
printf(GENERALTIME_VERSION"\n");
|
||||
printf(GENERALTIME_VERSION"\n");
|
||||
|
||||
if(!pgeneralTimePvt)
|
||||
{/* GeneralTime is not used, we just report version then quit */
|
||||
printf("General time framework is not initialized yet!\n\n");
|
||||
return epicsTimeOK;
|
||||
}
|
||||
if(!pgeneralTimePvt)
|
||||
{/* GeneralTime is not used, we just report version then quit */
|
||||
printf("General time framework is not initialized yet!\n\n");
|
||||
return epicsTimeOK;
|
||||
}
|
||||
|
||||
/* GeneralTime is in use, we try to report more detail */
|
||||
/* GeneralTime is in use, we try to report more detail */
|
||||
|
||||
/* we use sprintf instead of printf because we don't want to hold xxx_list_sem too long */
|
||||
/* we use sprintf instead of printf because we don't want to hold xxx_list_sem too long */
|
||||
|
||||
if(level>0)
|
||||
{
|
||||
printf("\nFor Time-Current-Provider:\n");
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
if(( items = ellCount( &(pgeneralTimePvt->tcp_list)) ))
|
||||
{
|
||||
ptempText = (char *)malloc(items * 80 * 3); /* for each provider, we print 3 lines, and each line is less then 80 bytes !!!!!!!! */
|
||||
if(!ptempText)
|
||||
{/* malloc failed */
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("Malloced memory for print out for %d tcps failed!\n", items);
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
if(GENERALTIME_DEBUG) printf("Malloced memory for print out for %d tcps\n", items);
|
||||
if(level>0)
|
||||
{
|
||||
printf("\nFor Time-Current-Provider:\n");
|
||||
epicsMutexMustLock( pgeneralTimePvt->tcp_list_sem );
|
||||
if(( items = ellCount( &(pgeneralTimePvt->tcp_list)) ))
|
||||
{
|
||||
ptempText = calloc(items, 80 * 3); /* for each provider, we print 3 lines, and each line is less then 80 bytes !!!!!!!! */
|
||||
if(!ptempText)
|
||||
{/* malloc failed */
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("Malloced memory for print out for %d tcps failed!\n", items);
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
if(GENERALTIME_DEBUG) printf("Malloced memory for print out for %d tcps\n", items);
|
||||
|
||||
bzero(ptempText, items*80*3);
|
||||
tempTextOffset = 0;
|
||||
tempTextOffset = 0;
|
||||
|
||||
for(ptcp=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcp; ptcp=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcp))
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t\"%s\",priority %d\n", ptcp->tp_desc, ptcp->tcp_priority);
|
||||
if(level>1)
|
||||
{
|
||||
tempTextOffset += sprintf( ptempText+tempTextOffset, "\t getCurrent is 0x%lx\n",
|
||||
(unsigned long)(ptcp->tcp_getCurrent) );
|
||||
if(ptcp->tcp_getCurrent)
|
||||
{
|
||||
status=(*(ptcp->tcp_getCurrent))(&tempTS);
|
||||
if(status!=epicsTimeERROR)
|
||||
{
|
||||
tempTSText[0]='\0';
|
||||
epicsTimeToStrftime(tempTSText, sizeof(tempTSText), "%Y/%m/%d %H:%M:%S.%06f",&tempTS);
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t Current Time is %s!\n", tempTSText);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t Time Current Provider \"%s\" Failed!\n", ptcp->tp_desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("%s", ptempText);
|
||||
free(ptempText);
|
||||
}
|
||||
else
|
||||
{
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("\tNo Time-Current-Provider registered!\n");
|
||||
}
|
||||
|
||||
printf("For Time-Event-Provider:\n");
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
if(( items = ellCount( &(pgeneralTimePvt->tep_list) ) ))
|
||||
{
|
||||
ptempText = (char *)malloc(items * 80 * 2); /* for each provider, we print 2 lines, and each line is less then 80 bytes !!!!!!!! */
|
||||
if(!ptempText)
|
||||
{/* malloc failed */
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("Malloced memory for print out for %d teps failed!\n", items);
|
||||
return epicsTimeERROR;
|
||||
for(ptcp=(TIME_CURRENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tcp_list) );
|
||||
ptcp; ptcp=(TIME_CURRENT_PROVIDER *)ellNext((ELLNODE *)ptcp))
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t\"%s\",priority %d\n", ptcp->tp_desc, ptcp->tcp_priority);
|
||||
if(level>1)
|
||||
{
|
||||
tempTextOffset += sprintf( ptempText+tempTextOffset, "\t getCurrent is 0x%lx\n",
|
||||
(unsigned long)(ptcp->tcp_getCurrent) );
|
||||
if(ptcp->tcp_getCurrent)
|
||||
{
|
||||
status=(*(ptcp->tcp_getCurrent))(&tempTS);
|
||||
if(status!=epicsTimeERROR)
|
||||
{
|
||||
tempTSText[0]='\0';
|
||||
epicsTimeToStrftime(tempTSText, sizeof(tempTSText), "%Y/%m/%d %H:%M:%S.%06f",&tempTS);
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t Current Time is %s!\n", tempTSText);
|
||||
}
|
||||
if(GENERALTIME_DEBUG) printf("Malloced memory for print out for %d teps\n", items);
|
||||
else
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset, "\t Time Current Provider \"%s\" Failed!\n", ptcp->tp_desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("%s", ptempText);
|
||||
free(ptempText);
|
||||
}
|
||||
else
|
||||
{
|
||||
epicsMutexUnlock( pgeneralTimePvt->tcp_list_sem );
|
||||
printf("\tNo Time-Current-Provider registered!\n");
|
||||
}
|
||||
|
||||
bzero(ptempText, items*80*2);
|
||||
tempTextOffset = 0;
|
||||
printf("For Time-Event-Provider:\n");
|
||||
epicsMutexMustLock( pgeneralTimePvt->tep_list_sem );
|
||||
if(( items = ellCount( &(pgeneralTimePvt->tep_list) ) ))
|
||||
{
|
||||
ptempText = (char *)malloc(items * 80 * 2); /* for each provider, we print 2 lines, and each line is less then 80 bytes !!!!!!!! */
|
||||
if(!ptempText)
|
||||
{/* malloc failed */
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("Malloced memory for print out for %d teps failed!\n", items);
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
if(GENERALTIME_DEBUG) printf("Malloced memory for print out for %d teps\n", items);
|
||||
|
||||
for(ptep=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptep; ptep=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptep))
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset,"\t\"%s\",priority %d\n",ptep->tp_desc,ptep->tep_priority);
|
||||
if(level>1)
|
||||
tempTextOffset += sprintf( ptempText+tempTextOffset, "\t getEvent is 0x%lx\n",(unsigned long)(ptep->tep_getEvent) );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("%s", ptempText);
|
||||
free(ptempText);
|
||||
}
|
||||
else
|
||||
{
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("\tNo Time-Event-Provider registered!\n");
|
||||
}
|
||||
bzero(ptempText, items*80*2);
|
||||
tempTextOffset = 0;
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
return epicsTimeOK;
|
||||
for(ptep=(TIME_EVENT_PROVIDER *)ellFirst( &(pgeneralTimePvt->tep_list) );
|
||||
ptep; ptep=(TIME_EVENT_PROVIDER *)ellNext((ELLNODE *)ptep))
|
||||
{
|
||||
tempTextOffset += sprintf(ptempText+tempTextOffset,"\t\"%s\",priority %d\n",ptep->tp_desc,ptep->tep_priority);
|
||||
if(level>1)
|
||||
tempTextOffset += sprintf( ptempText+tempTextOffset, "\t getEvent is 0x%lx\n",(unsigned long)(ptep->tep_getEvent) );
|
||||
}
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("%s", ptempText);
|
||||
free(ptempText);
|
||||
}
|
||||
else
|
||||
{
|
||||
epicsMutexUnlock( pgeneralTimePvt->tep_list_sem );
|
||||
printf("\tNo Time-Event-Provider registered!\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
return epicsTimeOK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -468,60 +467,60 @@ long generalTimeReport(int level)
|
||||
* 'generalTime' DTYP for ai, bo, longin and stringin records
|
||||
*/
|
||||
|
||||
int generalTimeGetCurrentDouble(double * pseconds) /* for ai record, seconds from 01/01/1990 */
|
||||
int generalTimeGetCurrentDouble(double * pseconds) /* for ai record, seconds from 01/01/1990 */
|
||||
{
|
||||
epicsTimeStamp ts;
|
||||
if(epicsTimeERROR!=epicsTimeGetCurrent(&ts))
|
||||
{
|
||||
*pseconds=ts.secPastEpoch+((double)(ts.nsec))*1e-9;
|
||||
return epicsTimeOK;
|
||||
}
|
||||
else
|
||||
return epicsTimeERROR;
|
||||
epicsTimeStamp ts;
|
||||
if(epicsTimeERROR!=epicsTimeGetCurrent(&ts))
|
||||
{
|
||||
*pseconds=ts.secPastEpoch+((double)(ts.nsec))*1e-9;
|
||||
return epicsTimeOK;
|
||||
}
|
||||
else
|
||||
return epicsTimeERROR;
|
||||
}
|
||||
|
||||
void generalTimeResetErrorCounts() /* for bo record */
|
||||
void generalTimeResetErrorCounts() /* for bo record */
|
||||
{
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
pgeneralTimePvt->ErrorCounts=0;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
pgeneralTimePvt->ErrorCounts=0;
|
||||
}
|
||||
|
||||
int generalTimeGetErrorCounts() /* for longin record */
|
||||
int generalTimeGetErrorCounts() /* for longin record */
|
||||
{
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
return pgeneralTimePvt->ErrorCounts;
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
return pgeneralTimePvt->ErrorCounts;
|
||||
}
|
||||
|
||||
void generalTimeGetBestTcp(char * desc) /* for stringin record */
|
||||
void generalTimeGetBestTcp(char * desc) /* for stringin record */
|
||||
{/* the assignment to pLastKnownBestTcp is atomic and desc is never changed after registeration */
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(pgeneralTimePvt->pLastKnownBestTcp)
|
||||
{/* We know some good tcp */
|
||||
strncpy(desc,pgeneralTimePvt->pLastKnownBestTcp->tp_desc,TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
else
|
||||
{/* no good tcp */
|
||||
strncpy(desc,"No Good Time-Current-Provider",TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(pgeneralTimePvt->pLastKnownBestTcp)
|
||||
{/* We know some good tcp */
|
||||
strncpy(desc,pgeneralTimePvt->pLastKnownBestTcp->tp_desc,TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
else
|
||||
{/* no good tcp */
|
||||
strncpy(desc,"No Good Time-Current-Provider",TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
}
|
||||
|
||||
void generalTimeGetBestTep(char * desc) /* for stringin record */
|
||||
void generalTimeGetBestTep(char * desc) /* for stringin record */
|
||||
{/* the assignment to pLastKnownBestTep is atomic and desc is never changed after registeration */
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(pgeneralTimePvt->pLastKnownBestTep)
|
||||
{/* We know some good tep */
|
||||
strncpy(desc,pgeneralTimePvt->pLastKnownBestTep->tp_desc,TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
else
|
||||
{/* no good tep */
|
||||
strncpy(desc,"No Good Time-Event-Provider",TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
if(!pgeneralTimePvt)
|
||||
generalTime_Init();
|
||||
if(pgeneralTimePvt->pLastKnownBestTep)
|
||||
{/* We know some good tep */
|
||||
strncpy(desc,pgeneralTimePvt->pLastKnownBestTep->tp_desc,TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
else
|
||||
{/* no good tep */
|
||||
strncpy(desc,"No Good Time-Event-Provider",TP_DESC_LEN-1);
|
||||
desc[TP_DESC_LEN-1]='\0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user