This is Unofficial EPICS BASE Doxygen Site
osdMonotonic.c File Reference
#include "dbDefs.h"
#include "errlog.h"
#include "epicsTime.h"
#include "generalTimeSup.h"
+ Include dependency graph for osdMonotonic.c:

Go to the source code of this file.

Macros

#define EPICS_EXPOSE_LIBCOM_MONOTONIC_PRIVATE
 

Functions

void osdMonotonicInit (void)
 
epicsUInt64 epicsMonotonicResolution (void)
 Monotonic time resolution, may not be accurate. Returns the minimum non-zero time difference between two calls to epicsMonotonicGet() in units of nanoseconds. More...
 
epicsUInt64 epicsMonotonicGet (void)
 Fetch monotonic counter, returns the number of nanoseconds since some unspecified time. More...
 

Macro Definition Documentation

#define EPICS_EXPOSE_LIBCOM_MONOTONIC_PRIVATE

Definition at line 7 of file osdMonotonic.c.

Function Documentation

epicsUInt64 epicsMonotonicGet ( void  )

Fetch monotonic counter, returns the number of nanoseconds since some unspecified time.

Definition at line 57 of file osdMonotonic.c.

58 {
59  struct timespec ts;
60  int ret = clock_gettime(osdMonotonicID, &ts);
61  if(ret) {
62  errlogPrintf("Warning: failed to fetch monotonic time %d %d\n",
63  (int)osdMonotonicID, ret);
64  return 0;
65  } else {
66  epicsUInt64 ret = ts.tv_sec;
67  ret *= 1000000000;
68  ret += ts.tv_nsec;
69  return ret;
70  }
71 }
unsigned long long epicsUInt64
Definition: epicsTypes.h:45
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
Defined by POSIX Real Time.
Definition: osdTime.h:21
epicsUInt64 epicsMonotonicResolution ( void  )

Monotonic time resolution, may not be accurate. Returns the minimum non-zero time difference between two calls to epicsMonotonicGet() in units of nanoseconds.

Definition at line 52 of file osdMonotonic.c.

53 {
54  return osdMonotonicResolution;
55 }
void osdMonotonicInit ( void  )

Definition at line 16 of file osdMonotonic.c.

17 {
18  unsigned i;
19 clockid_t ids[] = {
20 #ifdef CLOCK_HIGHRES
21  CLOCK_HIGHRES, /* solaris specific */
22 #endif
23 #ifdef CLOCK_MONOTONIC
24  CLOCK_MONOTONIC, /* Linux, RTEMS, and probably others */
25 #endif
26  /* fallback and vxWorks, not actually monotonic, but always available */
27  CLOCK_REALTIME
28  };
29 
30  for(i=0; i<NELEMENTS(ids); i++) {
31  epicsUInt64 res;
32  struct timespec ts;
33  int ret = clock_getres(ids[i], &ts);
34  if(ret) continue;
35 
36  res = ts.tv_sec;
37  res *= 1000000000;
38  res += ts.tv_nsec;
39 
40  /* fetch the time once to see that it actually succeeds */
41  ret = clock_gettime(ids[i], &ts);
42  if(ret) continue;
43 
44  osdMonotonicID = ids[i];
45  osdMonotonicResolution = res;
46  return;
47  }
48 
49  errMessage(errlogMinor, "Warning: failed to setup monotonic time source\n");
50 }
int i
Definition: scan.c:967
#define errMessage(S, PM)
Definition: errlog.h:48
unsigned long long epicsUInt64
Definition: epicsTypes.h:45
#define NELEMENTS(A)
Definition: aToIPAddr.c:21
Defined by POSIX Real Time.
Definition: osdTime.h:21