reuse timespec value for current-seconds-monotonic
This commit is contained in:
parent
30fcf62d73
commit
69ae22f678
|
@ -135,13 +135,17 @@
|
|||
;; things, for example on big-endian systems with 64 bit time_t and 32-bit long
|
||||
;;; (these might not actually exist)
|
||||
(define-cstruct _timespec ([tv-sec _long] [tv-nsec _long]))
|
||||
;; don't allocate a new timespec each call, just reuse the same one
|
||||
;; if a thread gets preempted in this call by another thread also in this call it won't cause
|
||||
;; any harmful effects
|
||||
(define singleton-timespec (make-timespec 0 0))
|
||||
(define *CLOCK-MONOTONIC* 1)
|
||||
(define *CLOCK-MONOTONIC-RAW* 4)
|
||||
(lambda ()
|
||||
(when (false? clock-gettime-call)
|
||||
(set! clock-gettime-call
|
||||
(get-ffi-obj/runtime "clock_gettime" (get-libc/init)
|
||||
(_fun #:save-errno 'posix _int (out : _timespec-pointer = (make-timespec 0 0))
|
||||
(_fun #:save-errno 'posix _int (out : _timespec-pointer = singleton-timespec)
|
||||
-> (res : _int)
|
||||
-> (if (zero? res)
|
||||
(timespec-tv-sec out)
|
||||
|
|
Loading…
Reference in New Issue