OSDN Git Service

* select.cc (select_stuff::wait): Temporarily disallow APCS.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / hires.h
1 /* hires.h: Definitions for hires clock calculations
2
3    Copyright 2002, 2003, 2004, 2005, 2009, 2010, 2011 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #ifndef __HIRES_H__
12 #define __HIRES_H__
13
14 #include <mmsystem.h>
15
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)
23
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)
31
32 /* 100ns difference between Windows and UNIX timebase. */
33 #define FACTOR (0x19db1ded53e8000LL)
34 /* # of 100ns intervals per second. */
35 #define NSPERSEC 10000000LL
36
37 class hires_base
38 {
39  protected:
40   int inited;
41  public:
42   void reset() {inited = false;}
43 };
44
45 class hires_ns : public hires_base
46 {
47   LARGE_INTEGER primed_pc;
48   double freq;
49   void prime ();
50  public:
51   LONGLONG nsecs ();
52   LONGLONG usecs () {return nsecs () / 1000LL;}
53   LONGLONG resolution();
54 };
55
56 class hires_ms : public hires_base
57 {
58   LONGLONG initime_ns;
59   LONGLONG timeGetTime_ns ();
60   void prime ();
61  public:
62   LONGLONG nsecs ();
63   LONGLONG usecs () {return nsecs () / 10LL;}
64   LONGLONG msecs () {return nsecs () / 10000LL;}
65   UINT dmsecs () { return timeGetTime_ns () / 10000LL; }
66   UINT resolution ();
67   LONGLONG uptime () {return (nsecs () - initime_ns) / 10000LL;}
68 };
69
70 extern hires_ms gtod;
71 #endif /*__HIRES_H__*/