-
Notifications
You must be signed in to change notification settings - Fork 6
/
time.lisp
40 lines (31 loc) · 1.01 KB
/
time.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(in-package #:scheduler)
#+sbcl
(defun unix-time ()
(multiple-value-bind (secs usecs)
(sb-ext:get-time-of-day)
(+ secs (* usecs 1.0d-6))))
#+ccl
(defun unix-time ()
(ccl:rlet ((tv :timeval))
(ccl::gettimeofday tv)
(multiple-value-bind (secs usecs)
(values (ccl:pref tv :timeval.tv_sec) (ccl:pref tv :timeval.tv_usec))
(+ secs (* usecs 1.0d-6)))))
#+ecl
(progn
(cffi:defctype time_t :long)
(cffi:defctype seconds_t :int)
(cffi:defcstruct timeval
(tv_sec time_t)
(tv_usec seconds_t))
(cffi:defcfun gettimeofday :int
(timeval :pointer)
(pointer :pointer))
(defun unix-time ()
(cffi:with-foreign-object (tv '(:struct timeval))
(gettimeofday tv (cffi::null-pointer))
(+ (cffi:mem-ref tv 'time_t) (* (cffi:mem-ref tv 'seconds_t (cffi:foreign-type-size 'time_t)) 1.0d-6)))))
(defun quant (next-time &optional time)
"Return a time which quantized to given a next-time."
(let ((time (* 1.0d0 (floor time))))
(+ time (- next-time (mod time next-time)))))