Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-06-07 07:44:33 +0400
committerChristopher Faylor <me@cgf.cx>2002-06-07 07:44:33 +0400
commit9d0efbb3aeef0490d227c9b98bd478ac1964d16d (patch)
tree005964002ffa58bbddce64254ce2b60cfc9e0d59
parentb841df7954ad31383688775114132af73b7693d4 (diff)
* autoload.cc (timeGetDevCaps): Define new autoload function.
(timeGetTime): Ditto. (timeBeginPeriod): Ditto. (timeEndPeriod): Ditto. * hires.h (hires_base): New class. Renamed from hires. (hires_us): New class. (hires_ms): New class. * strace.cc (strace::microseconds): Use hires_us class. * times.cc (gettimeofday): Use hires-ms class. (hires_us::prime): Renamed from hires::prime. (hires_us::usecs): Renamed from hires:usecs. (hires_ms::prime): New method. (hires_ms::usecs): New method. (hires_ms::~hires_ms): New destructor.
-rw-r--r--winsup/cygwin/ChangeLog17
-rw-r--r--winsup/cygwin/autoload.cc4
-rw-r--r--winsup/cygwin/hires.h29
-rw-r--r--winsup/cygwin/strace.cc2
-rw-r--r--winsup/cygwin/times.cc47
5 files changed, 91 insertions, 8 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 75d49d070..245767779 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,22 @@
2002-06-06 Christopher Faylor <cgf@redhat.com>
+ * autoload.cc (timeGetDevCaps): Define new autoload function.
+ (timeGetTime): Ditto.
+ (timeBeginPeriod): Ditto.
+ (timeEndPeriod): Ditto.
+ * hires.h (hires_base): New class. Renamed from hires.
+ (hires_us): New class.
+ (hires_ms): New class.
+ * strace.cc (strace::microseconds): Use hires_us class.
+ * times.cc (gettimeofday): Use hires-ms class.
+ (hires_us::prime): Renamed from hires::prime.
+ (hires_us::usecs): Renamed from hires:usecs.
+ (hires_ms::prime): New method.
+ (hires_ms::usecs): New method.
+ (hires_ms::~hires_ms): New destructor.
+
+2002-06-06 Christopher Faylor <cgf@redhat.com>
+
* autoload.cc (noload): Correctly save argument count register.
2002-06-05 Conrad Scott <conrad.scott@dsl.pipex.com>
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index 7776896e3..9bae17deb 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -504,4 +504,8 @@ LoadDLLfuncEx (waveOutSetVolume, 8, winmm, 1)
LoadDLLfuncEx (waveOutUnprepareHeader, 12, winmm, 1)
LoadDLLfuncEx (waveOutPrepareHeader, 12, winmm, 1)
LoadDLLfuncEx (waveOutWrite, 12, winmm, 1)
+LoadDLLfuncEx (timeGetDevCaps, 8, winmm, 1)
+LoadDLLfuncEx (timeGetTime, 0, winmm, 1)
+LoadDLLfuncEx (timeBeginPeriod, 4, winmm, 1)
+LoadDLLfuncEx (timeEndPeriod, 4, winmm, 1)
}
diff --git a/winsup/cygwin/hires.h b/winsup/cygwin/hires.h
index c341aa287..611b2df0d 100644
--- a/winsup/cygwin/hires.h
+++ b/winsup/cygwin/hires.h
@@ -11,14 +11,37 @@ details. */
#ifndef __HIRES_H__
#define __HIRES_H__
-class hires
+#include <mmsystem.h>
+
+class hires_base
{
+ protected:
int inited;
+ virtual void prime () {}
+ public:
+ virtual LONGLONG usecs (bool justdelta) {return 0LL;}
+ virtual ~hires_base () {}
+};
+
+class hires_us : hires_base
+{
LARGE_INTEGER primed_ft;
LARGE_INTEGER primed_pc;
double freq;
- void prime () __attribute__ ((regparm (1)));
+ void prime ();
+ public:
+ LONGLONG usecs (bool justdelta);
+};
+
+class hires_ms : hires_base
+{
+ DWORD initime_ms;
+ LARGE_INTEGER initime_us;
+ UINT minperiod;
+ void prime ();
public:
- LONGLONG usecs (bool justdelta) __attribute__ ((regparm (2)));
+ LONGLONG usecs (bool justdelta);
+ ~hires_ms ();
};
+
#endif /*__HIRES_H__*/
diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc
index f0eb799da..5a4549161 100644
--- a/winsup/cygwin/strace.cc
+++ b/winsup/cygwin/strace.cc
@@ -63,7 +63,7 @@ strace::hello()
int
strace::microseconds ()
{
- static hires now;
+ static hires_us now;
return (int) now.usecs (true);
}
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index a81201e7b..a64ee3d86 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -143,9 +143,9 @@ totimeval (struct timeval *dst, FILETIME *src, int sub, int flag)
/* FIXME: Make thread safe */
extern "C" int
-gettimeofday(struct timeval *tv, struct timezone *tz)
+gettimeofday (struct timeval *tv, struct timezone *tz)
{
- static hires gtod;
+ static hires_ms gtod;
static bool tzflag;
LONGLONG now = gtod.usecs (false);
if (now == (LONGLONG) -1)
@@ -580,7 +580,7 @@ cygwin_tzset ()
}
void
-hires::prime ()
+hires_us::prime ()
{
LARGE_INTEGER ifreq;
if (!QueryPerformanceFrequency (&ifreq))
@@ -612,7 +612,7 @@ hires::prime ()
}
LONGLONG
-hires::usecs (bool justdelta)
+hires_us::usecs (bool justdelta)
{
if (!inited)
prime ();
@@ -633,3 +633,42 @@ hires::usecs (bool justdelta)
now.QuadPart = (LONGLONG) (freq * (double) (now.QuadPart - primed_pc.QuadPart));
return justdelta ? now.QuadPart : primed_ft.QuadPart + now.QuadPart;
}
+
+void
+hires_ms::prime ()
+{
+ TIMECAPS tc;
+ FILETIME f;
+ int priority = GetThreadPriority (GetCurrentThread ());
+ SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
+
+ if (timeGetDevCaps (&tc, sizeof (tc)) != TIMERR_NOERROR)
+ minperiod = 0;
+ else
+ {
+ minperiod = min (max(tc.wPeriodMin, 1), tc.wPeriodMax);
+ timeBeginPeriod (minperiod);
+ }
+ initime_ms = timeGetTime ();
+ GetSystemTimeAsFileTime (&f);
+ SetThreadPriority (GetCurrentThread (), priority);
+ initime_us.HighPart = f.dwHighDateTime;
+ initime_us.LowPart = f.dwLowDateTime;
+ initime_us.QuadPart /= 10;
+}
+
+LONGLONG
+hires_ms::usecs (bool justdelta)
+{
+ if (!inited)
+ prime ();
+ DWORD now = timeGetTime ();
+ // FIXME: Not sure how this will handle the 49.71 day wrap around
+ LONGLONG res = initime_us.QuadPart + ((LONGLONG) (now - initime_ms) * 1000);
+ return res;
+}
+
+hires_ms::~hires_ms ()
+{
+ timeEndPeriod (minperiod);
+}