[pypy-svn] r46259 - pypy/branch/pypy-more-rtti-inprogress/rpython/module
arigo at codespeak.net
arigo at codespeak.net
Mon Sep 3 11:33:27 CEST 2007
Author: arigo
Date: Mon Sep 3 11:33:27 2007
New Revision: 46259
Modified:
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py
Log:
finish ll_time -> win.
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py Mon Sep 3 11:33:27 2007
@@ -97,9 +97,28 @@
@registering(time.clock)
def register_time_clock(self):
c_clock = self.llexternal('clock', [], self.CLOCK_T)
-
if sys.platform == 'win32':
- xxx
+ # hacking to avoid LARGE_INTEGER which is a union...
+ A = lltype.FixedSizeArray(lltype.SignedLongLong, 1)
+ QueryPerformanceCounter = self.llexternal(
+ 'QueryPerformanceCounter', [lltype.Ptr(A)], lltype.Void)
+ QueryPerformanceFrequency = self.llexternal(
+ 'QueryPerformanceFrequency', [lltype.Ptr(A)], rffi.INT)
+ class State(object):
+ pass
+ state = State()
+ state.divisor = 0.0
+ def time_clock_llimpl():
+ a = lltype.malloc(A, flavor='raw')
+ if state.divisor == 0.0:
+ QueryPerformanceCounter(a)
+ state.counter_start = a[0]
+ QueryPerformanceFrequency(a)
+ state.divisor = float(a[0])
+ QueryPerformanceCounter(a)
+ diff = a[0] - state.counter_start
+ lltype.free(a, flavor='raw')
+ return float(diff) / state.divisor
else:
def time_clock_llimpl():
result = c_clock()
@@ -111,15 +130,20 @@
@registering(time.sleep)
def register_time_sleep(self):
if sys.platform == 'win32':
- xxx
+ MAX = sys.maxint
+ Sleep = self.llexternal('Sleep', [rffi.ULONG], lltype.Void)
+ def time_sleep_llimpl(secs):
+ millisecs = secs * 1000.0
+ while millisecs > MAX:
+ Sleep(MAX)
+ millisecs -= MAX
+ Sleep(rffi.cast(rffi.ULONG, int(millisecs)))
else:
c_select = self.llexternal('select', [rffi.INT, rffi.VOIDP,
rffi.VOIDP, rffi.VOIDP,
self.TIMEVALP], rffi.INT)
def time_sleep_llimpl(secs):
- # XXX cannot put it into try: finally: because
- # someone forgotten to call hop.exception_is_here
void = lltype.nullptr(rffi.VOIDP.TO)
t = lltype.malloc(self.TIMEVAL, flavor='raw')
try:
More information about the pypy-svn
mailing list