Changeset 10651


Ignore:
Timestamp:
Sep 8, 2008, 8:40:47 AM (11 years ago)
Author:
gb
Message:

Windows changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lib/time.lisp

    r10445 r10651  
    4646  "Return a single integer for the current time of
    4747   day in universal time format."
     48  #-windows-target
    4849  (rlet ((tv :timeval))
    4950    (#_gettimeofday tv (%null-ptr))
    50     (+ (pref tv :timeval.tv_sec) unix-to-universal-time)))
     51    (+ (pref tv :timeval.tv_sec) unix-to-universal-time))
     52  #+windows-target
     53  (rlet ((ft #>FILETIME))
     54    (#_GetSystemTimeAsFileTime ft)
     55    (windows-filetime-to-universal-time ft)))
     56
    5157
    5258;;; This should stop using #_localtime_r: not all times can be represented
     
    5460;;; For now, if the time won't fit in a :time_t, use an arbitrary time
    5561;;; value to get the time zone and assume that DST was -not- in effect.
     62#-windows-target
    5663(defun get-timezone (time)
    5764  (let* ((toobig (not (typep time '(signed-byte
     
    7178                           -60)
    7279                    (unless toobig (not (zerop (pref tm :tm.tm_isdst)))))))))))
     80
     81#+windows-target
     82(defun get-timezone (time)
     83  (declare (ignore time))
     84  (rlet ((tzinfo #>TIME_ZONE_INFORMATION))
     85    (let* ((id (#_GetTimeZoneInformation tzinfo))
     86           (minutes-west (pref tzinfo #>TIME_ZONE_INFORMATION.Bias))
     87           (is-dst (= id #$TIME_ZONE_ID_DAYLIGHT)))
     88      (values (floor (+ minutes-west
     89                        (if is-dst
     90                          (pref tzinfo #>TIME_ZONE_INFORMATION.DaylightBias)
     91                          0)))
     92              is-dst))))
    7393
    7494
     
    196216  be any non-negative, non-complex number."
    197217  (when (minusp seconds) (report-bad-arg seconds '(real 0 *)))
     218  #-windows-target
    198219  (multiple-value-bind (secs nanos)
    199220      (nanoseconds seconds)
    200     (%nanosleep secs nanos)))
    201 
    202 (defun get-internal-run-time ()
    203   "Return the run time in the internal time format. (See
    204   INTERNAL-TIME-UNITS-PER-SECOND.) This is useful for finding CPU usage."
     221    (%nanosleep secs nanos))
     222  #+windows-target
     223  (let* ((millis (round (* seconds 1000))))
     224    (#_SleepEx millis 1)
     225    nil))
     226
     227
     228(defun %internal-run-time ()
     229  ;; Returns user and system times in internal-time-units as multiple values.
     230  #-windows-target
    205231  (rlet ((usage :rusage))
    206232    (%%rusage usage)
     
    209235           (user-micros (pref usage :rusage.ru_utime.tv_usec))
    210236           (system-micros (pref usage :rusage.ru_stime.tv_usec)))
    211       (+ (* (+ user-seconds system-seconds) internal-time-units-per-second)
    212          (round (+ user-micros system-micros) (floor 1000000 internal-time-units-per-second))))))
     237      (values (+ (* user-seconds internal-time-units-per-second)
     238                 (round user-micros (floor 1000000 internal-time-units-per-second)))
     239              (+ (* system-seconds internal-time-units-per-second)
     240                 (round system-micros (floor 1000000 internal-time-units-per-second))))))
     241  #+windows-target
     242  (rlet ((start #>FILETIME)
     243         (end #>FILETIME)
     244         (kernel #>FILETIME)
     245         (user #>FILETIME))
     246    (#_GetProcessTimes (#_GetCurrentProcess) start end kernel user)
     247    (let* ((user-100ns (dpb (pref user #>FILETIME.dwHighDateTime)
     248                            (byte 32 32)
     249                            (pref user #>FILETIME.dwLowDateTime)))
     250           (kernel-100ns (dpb (pref kernel #>FILETIME.dwHighDateTime)
     251                            (byte 32 32)
     252                            (pref kernel #>FILETIME.dwLowDateTime)))
     253           (convert (floor 10000000 internal-time-units-per-second)))
     254      (values (floor user-100ns convert) (floor kernel-100ns convert)))))
     255
     256(defun get-internal-run-time ()
     257  "Return the run time in the internal time format. (See
     258  INTERNAL-TIME-UNITS-PER-SECOND.) This is useful for finding CPU usage."
     259  (multiple-value-bind (user sys) (%internal-run-time)
     260    (+ user sys)))
    213261
    214262
Note: See TracChangeset for help on using the changeset viewer.