;;;; (module current-nanoseconds (;export ;special current-flnanoseconds ; current-nanoseconds) (import scheme (chicken base) (chicken type) (chicken foreign)) (: current-flnanoseconds (-> float)) (: current-nanoseconds (-> integer)) ;NOTE platforms have different epochs (macOS & Unix: ~311 days) ;however these timings are not treated as a calendar time (: get-nanosecs (-> integer)) (cond-expand (macosx (include "macosx") ) (unix (include "unix") ) (windows (include "windows") ) (else (error "unsupported platform") ) ) (cond-expand (reliable-time (define-syntax current-flnanoseconds (syntax-rules () ((_) (exact->inexact (current-nanoseconds))) ) ) ) (eventual-time (define-syntax current-flnanoseconds (syntax-rules () ((_) (let loop ((ns (current-nanoseconds))) (unless (positive? ns) (loop (current-nanoseconds))) (exact->inexact ns) ) ) ) ) ) (else ;warning-time (import (chicken module)) (export $warn-unreliable-time) (: $warn-unreliable-time (integer -> void)) (define ($warn-unreliable-time ns) (warning 'current-nanoseconds "cannot retrieve time reliably" ns) ) (define-syntax current-flnanoseconds (syntax-rules () ((_) (let ((ns (current-nanoseconds))) (unless (positive? ns) ($warn-unreliable-time ns)) (exact->inexact ns) ) ) ) ) ) ) (define current-nanoseconds get-nanosecs) ) ;module current-nanoseconds