This is Unofficial EPICS BASE Doxygen Site
osdMonotonic.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2015 Michael Davidsaver
3 * EPICS BASE is distributed subject to a Software License Agreement found
4 * in file LICENSE that is included with this distribution.
5 \*************************************************************************/
6 
7 #include <windows.h>
8 
9 #define EPICS_EXPOSE_LIBCOM_MONOTONIC_PRIVATE
10 #include "dbDefs.h"
11 #include "errlog.h"
12 #include "epicsTime.h"
13 #include "generalTimeSup.h"
14 
15 static unsigned char osdUsePrefCounter;
16 static epicsUInt64 osdMonotonicResolution;
17 
18 void osdMonotonicInit(void)
19 {
20  LARGE_INTEGER freq, val;
21 
22  if(!QueryPerformanceFrequency(&freq) ||
23  !QueryPerformanceCounter(&val))
24  {
25  double period = 1.0/freq.QuadPart;
26  osdMonotonicResolution = period*1e9;
27  osdUsePrefCounter = 1;
28  } else {
29  osdMonotonicResolution = 1e6; /* 1 ms TODO place holder */
30  }
31 }
32 
34 {
35  return osdMonotonicResolution;
36 }
37 
39 {
40  LARGE_INTEGER val;
41  if(osdUsePrefCounter) {
42  if(!QueryPerformanceCounter(&val)) {
43  errMessage(errlogMinor, "Warning: failed to fetch performance counter\n");
44  return 0;
45  } else
46  return val.QuadPart;
47  } else {
48  epicsUInt64 ret = GetTickCount();
49  ret *= 1000000;
50  return ret;
51  }
52 }
void osdMonotonicInit(void)
Definition: osdMonotonic.c:19
epicsUInt64 epicsMonotonicGet(void)
Fetch monotonic counter, returns the number of nanoseconds since some unspecified time...
Definition: osdMonotonic.c:29
#define errMessage(S, PM)
Definition: errlog.h:48
Miscellaneous macro definitions.
unsigned long long epicsUInt64
Definition: epicsTypes.h:45
epicsUInt64 epicsMonotonicResolution(void)
Monotonic time resolution, may not be accurate. Returns the minimum non-zero time difference between ...
Definition: osdMonotonic.c:24
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...