1 /* hires.h: Definitions for hires clock calculations
3 Copyright 2002, 2003, 2004, 2005, 2009, 2010, 2011 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
16 /* Conversions for per-process and per-thread clocks */
17 #define PID_TO_CLOCKID(pid) (pid * 8 + CLOCK_PROCESS_CPUTIME_ID)
18 #define CLOCKID_TO_PID(cid) ((cid - CLOCK_PROCESS_CPUTIME_ID) / 8)
19 #define CLOCKID_IS_PROCESS(cid) ((cid % 8) == CLOCK_PROCESS_CPUTIME_ID)
20 #define THREADID_TO_CLOCKID(tid) (tid * 8 + CLOCK_THREAD_CPUTIME_ID)
21 #define CLOCKID_TO_THREADID(cid) ((cid - CLOCK_THREAD_CPUTIME_ID) / 8)
22 #define CLOCKID_IS_THREAD(cid) ((cid % 8) == CLOCK_THREAD_CPUTIME_ID)
24 /* Largest delay in ms for sleep and alarm calls.
25 Allow actual delay to exceed requested delay by 10 s.
26 Express as multiple of 1000 (i.e. seconds) + max resolution
27 The tv_sec argument in timeval structures cannot exceed
28 HIRES_DELAY_MAX / 1000 - 1, so that adding fractional part
29 and rounding won't exceed HIRES_DELAY_MAX */
30 #define HIRES_DELAY_MAX ((((UINT_MAX - 10000) / 1000) * 1000) + 10)
32 /* 100ns difference between Windows and UNIX timebase. */
33 #define FACTOR (0x19db1ded53e8000LL)
34 /* # of 100ns intervals per second. */
35 #define NSPERSEC 10000000LL
42 void reset() {inited = false;}
45 class hires_ns : public hires_base
47 LARGE_INTEGER primed_pc;
52 LONGLONG usecs () {return nsecs () / 1000LL;}
53 LONGLONG resolution();
56 class hires_ms : public hires_base
59 LONGLONG timeGetTime_ns ();
63 LONGLONG usecs () {return nsecs () / 10LL;}
64 LONGLONG msecs () {return nsecs () / 10000LL;}
65 UINT dmsecs () { return timeGetTime_ns () / 10000LL; }
67 LONGLONG uptime () {return (nsecs () - initime_ns) / 10000LL;}
71 #endif /*__HIRES_H__*/