package time_now

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file time_now.ml

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
[%%import "config.h"]

open! Base

[%%ifdef JSC_ARCH_SIXTYFOUR]

external nanoseconds_since_unix_epoch_or_zero
  :  unit
  -> Int63.t
  = "time_now_nanoseconds_since_unix_epoch_or_zero"
[@@noalloc]

[%%else]

external nanoseconds_since_unix_epoch_or_zero
  :  unit
  -> Int63.t
  = "time_now_nanoseconds_since_unix_epoch_or_zero"

[%%endif]
[%%ifdef JSC_POSIX_TIMERS]

let[@cold] gettime_failed () = failwith "clock_gettime(CLOCK_REALTIME) failed"

[%%else]

let[@cold] gettime_failed () = failwith "gettimeofday failed"

[%%endif]

let nanoseconds_since_unix_epoch () =
  let t = nanoseconds_since_unix_epoch_or_zero () in
  if Int63.( <> ) t Int63.zero then t else gettime_failed ()
;;
OCaml

Innovation. Community. Security.