nSec => nsec (TS_STAMP fields)

This commit is contained in:
Jeff Hill
1999-12-23 01:01:15 +00:00
parent 9580811806
commit 0885e029d4
4 changed files with 100 additions and 73 deletions

View File

@@ -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) {

View File

@@ -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<time_t> (-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)

View File

@@ -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 (&current);
# 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 (&current, 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;
}

View File

@@ -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;