]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/hires.h
Cygwin: Cleanup time handling
[newlib-cygwin.git] / winsup / cygwin / hires.h
1 /* hires.h: Definitions for hires clock calculations
2
3 This file is part of Cygwin.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #ifndef __HIRES_H__
10 #define __HIRES_H__
11
12 #include <mmsystem.h>
13
14 /* Conversions for per-process and per-thread clocks */
15 #define PID_TO_CLOCKID(pid) (pid * 8 + CLOCK_PROCESS_CPUTIME_ID)
16 #define CLOCKID_TO_PID(cid) ((cid - CLOCK_PROCESS_CPUTIME_ID) / 8)
17 #define CLOCKID_IS_PROCESS(cid) ((cid % 8) == CLOCK_PROCESS_CPUTIME_ID)
18 #define THREADID_TO_CLOCKID(tid) (tid * 8 + CLOCK_THREAD_CPUTIME_ID)
19 #define CLOCKID_TO_THREADID(cid) ((cid - CLOCK_THREAD_CPUTIME_ID) / 8)
20 #define CLOCKID_IS_THREAD(cid) ((cid % 8) == CLOCK_THREAD_CPUTIME_ID)
21
22 /* Largest delay in ms for sleep and alarm calls.
23 Allow actual delay to exceed requested delay by 10 s.
24 Express as multiple of 1000 (i.e. seconds) + max resolution
25 The tv_sec argument in timeval structures cannot exceed
26 HIRES_DELAY_MAX / 1000 - 1, so that adding fractional part
27 and rounding won't exceed HIRES_DELAY_MAX */
28 #define HIRES_DELAY_MAX ((((UINT_MAX - 10000) / 1000) * 1000) + 10)
29
30 /* 100ns difference between Windows and UNIX timebase. */
31 #define FACTOR (0x19db1ded53e8000LL)
32 /* # of nanosecs per second. */
33 #define NSPERSEC (1000000000)
34 /* # of 100ns intervals per second. */
35 #define NS100PERSEC (10000000)
36 /* # of millisecs per second. */
37 #define USPERSEC (1000000)
38
39 class hires_base
40 {
41 protected:
42 int inited;
43 public:
44 void reset() {inited = false;}
45 };
46
47 class hires_ns : public hires_base
48 {
49 LARGE_INTEGER primed_pc;
50 double freq;
51 void prime ();
52 public:
53 LONGLONG nsecs (bool monotonic = false);
54 LONGLONG usecs () {return nsecs () / 1000LL;}
55 LONGLONG resolution();
56 };
57
58 class hires_ms : public hires_base
59 {
60 public:
61 LONGLONG nsecs ();
62 LONGLONG usecs () {return nsecs () / 10LL;}
63 LONGLONG msecs () {return nsecs () / 10000LL;}
64 UINT resolution ();
65 };
66
67 extern hires_ms gtod;
68 #endif /*__HIRES_H__*/
This page took 0.039212 seconds and 5 git commands to generate.