From 0885e029d40e0c20571c205df4f977ae87ef9197 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 23 Dec 1999 01:01:15 +0000 Subject: [PATCH] nSec => nsec (TS_STAMP fields) --- src/libCom/osi/os/WIN32/osdTime.cpp | 2 +- src/libCom/osi/osiTime.cpp | 138 +++++++++++++++++----------- src/libCom/osi/osiTime.h | 31 +++---- src/libCom/osi/tsStamp.h | 2 +- 4 files changed, 100 insertions(+), 73 deletions(-) diff --git a/src/libCom/osi/os/WIN32/osdTime.cpp b/src/libCom/osi/os/WIN32/osdTime.cpp index e3efab94d..1af6219d9 100644 --- a/src/libCom/osi/os/WIN32/osdTime.cpp +++ b/src/libCom/osi/os/WIN32/osdTime.cpp @@ -358,7 +358,7 @@ extern "C" epicsShareFunc int epicsShareAPI tsStampGetCurrent (TS_STAMP *pDest) perf_last = time_cur; pDest->secPastEpoch = (unsigned long) (time_sec%ULONG_MAX); - pDest->nSec = (unsigned long) ((time_remainder*osiTime::nSecPerSec)/perf_freq); + pDest->nsec = (unsigned long) ((time_remainder*osiTime::nSecPerSec)/perf_freq); status = ReleaseMutex (osdTimeMutex); if (!status) { diff --git a/src/libCom/osi/osiTime.cpp b/src/libCom/osi/osiTime.cpp index aed66b124..52c4915aa 100644 --- a/src/libCom/osi/osiTime.cpp +++ b/src/libCom/osi/osiTime.cpp @@ -246,12 +246,13 @@ osiTime::operator tm_nano_sec () const ansiTimeTicks = *this; + // // reentrant version of localtime() - from POSIX RT - // WRS prototype is incorrect ? + // + // ???? WRS prototype is incorrect ???? + // p = localtime_r (&ansiTimeTicks.ts, &tm.ansi_tm); - if (p != &tm.ansi_tm) { - throw internalFailure (); - } + assert (p == &tm.ansi_tm); tm.nSec = this->nSec; @@ -263,20 +264,24 @@ osiTime::operator tm_nano_sec () const // osiTime::osiTime (const tm_nano_sec &tm) { + static const time_t mktimeFailure = static_cast (-1); time_t_wrapper ansiTimeTicks; struct tm tmp = tm.ansi_tm; ansiTimeTicks.ts = mktime (&tmp); - if (ansiTimeTicks.ts==(time_t)-1) { - throw formatProblemWithStructTM (); + if (ansiTimeTicks.ts == mktimeFailure) { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw formatProblemWithStructTM (); +# endif } *this = osiTime (ansiTimeTicks); - if (tm.nSec>=nSecPerSec) { - throw nanoSecFieldIsTooLarge (); - } - *this = osiTime (this->secPastEpoch, this->nSec + tm.nSec); + unsigned long nSecAdj = tm.nSec % nSecPerSec; + unsigned long secAdj = tm.nSec / nSecPerSec; + *this = osiTime (this->secPastEpoch+secAdj, this->nSec+nSecAdj); } // @@ -355,10 +360,9 @@ osiTime::osiTime (const aitTimeStamp &ts) ansiTimeTicks.ts = ts.tv_sec; *this = osiTime (ansiTimeTicks); - if ( ts.tv_nsec>=nSecPerSec ) { - throw nanoSecFieldIsTooLarge (); - } - *this = osiTime ( this->secPastEpoch, this->nSec + ts.tv_nsec ); + unsigned long secAdj = ts.tv_nsec / nSecPerSec; + unsigned long nSecAdj = ts.tv_nsec % nSecPerSec; + *this = osiTime (this->secPastEpoch+secAdj, this->nSec+nSecAdj); } // @@ -647,71 +651,97 @@ extern "C" { // epicsShareFunc int epicsShareAPI tsStampToTime_t (time_t *pDest, const TS_STAMP *pSrc) { - try { - time_t_wrapper dst; - dst = osiTime (*pSrc); +# ifdef noExceptionsFromCXX + time_t_wrapper dst = osiTime (*pSrc); *pDest = dst.ts; - } - catch (...) { - return tsStampERROR; - } +# else + try { + time_t_wrapper dst = osiTime (*pSrc); + *pDest = dst.ts; + } + catch (...) { + return tsStampERROR; + } +# endif return tsStampOK; } epicsShareFunc int epicsShareAPI tsStampFromTime_t (TS_STAMP *pDest, time_t src) { - try { - time_t_wrapper dst; - dst.ts = src; + time_t_wrapper dst; + dst.ts = src; +# ifdef noExceptionsFromCXX *pDest = osiTime (dst); - } - catch (...) { - return tsStampERROR; - } +# else + try { + *pDest = osiTime (dst); + } + catch (...) { + return tsStampERROR; + } +# endif return tsStampOK; } epicsShareFunc int epicsShareAPI tsStampToTM (struct tm *pDest, unsigned long *pNSecDest, const TS_STAMP *pSrc) { - try { - tm_nano_sec tmns = osiTime (*pSrc); - *pDest = tmns.ansi_tm; - *pNSecDest = tmns.nSec; - } - catch (...) { - return tsStampERROR; - } + tm_nano_sec tmns; +# ifdef noExceptionsFromCXX + tmns = osiTime (*pSrc); +# else + try { + tmns = osiTime (*pSrc); + } + catch (...) { + return tsStampERROR; + } +# endif + *pDest = tmns.ansi_tm; + *pNSecDest = tmns.nSec; return tsStampOK; } epicsShareFunc int epicsShareAPI tsStampFromTM (TS_STAMP *pDest, const struct tm *pSrc, unsigned long nSecSrc) { - try { - tm_nano_sec tmns; - tmns.ansi_tm = *pSrc; - tmns.nSec = nSecSrc; + tm_nano_sec tmns; + tmns.ansi_tm = *pSrc; + tmns.nSec = nSecSrc; + +# ifdef noExceptionsFromCXX *pDest = osiTime (tmns); - } - catch (...) { - return tsStampERROR; - } +# else + try { + *pDest = osiTime (tmns); + } + catch (...) { + return tsStampERROR; + } +# endif return tsStampOK; } epicsShareFunc int epicsShareAPI tsStampToTimespec (struct timespec *pDest, const TS_STAMP *pSrc) { - try { +# ifdef noExceptionsFromCXX *pDest = osiTime (*pSrc); - } - catch (...) { - return tsStampERROR; - } +# else + try { + *pDest = osiTime (*pSrc); + } + catch (...) { + return tsStampERROR; + } +# endif return tsStampOK; } epicsShareFunc int epicsShareAPI tsStampFromTimespec (TS_STAMP *pDest, const struct timespec *pSrc) { - try { +# ifdef noExceptionsFromCXX *pDest = osiTime (*pSrc); - } - catch (...) { - return tsStampERROR; - } +# else + try { + *pDest = osiTime (*pSrc); + } + catch (...) { + return tsStampERROR; + } +# endif return tsStampOK; } epicsShareFunc long double epicsShareAPI tsStampDiffInSeconds (const TS_STAMP *pLeft, const TS_STAMP *pRight) diff --git a/src/libCom/osi/osiTime.h b/src/libCom/osi/osiTime.h index 1d2daef2f..30f72fd52 100644 --- a/src/libCom/osi/osiTime.h +++ b/src/libCom/osi/osiTime.h @@ -120,10 +120,7 @@ public: // exceptions // class unableToFetchCurrentTime {}; - class negNanoSecInTimeStampFromUNIX {}; - class nanoSecFieldIsTooLarge {}; class formatProblemWithStructTM {}; - class internalFailure {}; // // fetch the current time @@ -256,13 +253,13 @@ inline osiTime osiTime::getCurrent () int status; status = tsStampGetCurrent (¤t); -# ifdef osiTimeCanThrowException - if (status) { + if (status) { +# ifdef noExceptionsFromCXX + assert (0); +# else throw unableToFetchCurrentTime (); - } -# else - assert (!status); -# endif +# endif + } return osiTime (current); } @@ -273,13 +270,13 @@ inline osiTime osiTime::getEvent (const osiTimeEvent &event) int status; status = tsStampGetEvent (¤t, event.eventNumber); -# ifdef osiTimeCanThrowException - if (status) { + if (status) { +# ifdef noExceptionsFromCXX + assert (0); +# else throw unableToFetchCurrentTime (); - } -# else - assert (!status); -# endif +# endif + } return osiTime (current); } @@ -353,7 +350,7 @@ inline osiTime osiTime::operator = (const aitTimeStamp &rhs) inline osiTime::osiTime (const TS_STAMP &ts) { this->secPastEpoch = ts.secPastEpoch; - this->nSec = ts.nSec; + this->nSec = ts.nsec; } inline osiTime osiTime::operator = (const TS_STAMP &rhs) @@ -366,7 +363,7 @@ inline osiTime::operator TS_STAMP () const { TS_STAMP ts; ts.secPastEpoch = this->secPastEpoch; - ts.nSec = this->nSec; + ts.nsec = this->nSec; return ts; } diff --git a/src/libCom/osi/tsStamp.h b/src/libCom/osi/tsStamp.h index 44395b1c6..2c74cb90b 100644 --- a/src/libCom/osi/tsStamp.h +++ b/src/libCom/osi/tsStamp.h @@ -35,7 +35,7 @@ struct timespec; */ typedef struct TS_STAMP { epicsUInt32 secPastEpoch; /* seconds since 0000 Jan 1, 1990 */ - epicsUInt32 nSec; /* nanoseconds within second */ + epicsUInt32 nsec; /* nanoseconds within second */ } TS_STAMP;