Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / basis-library / mlton / itimer.sml
CommitLineData
7f918cf1
CE
1(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9structure MLtonItimer =
10 struct
11 structure Prim = PrimitiveFFI.MLton.Itimer
12
13 datatype t = Prof | Real | Virtual
14
15 val signal =
16 fn Prof => PosixSignal.prof
17 | Real => PosixSignal.alrm
18 | Virtual => PosixSignal.vtalrm
19
20 val toInt =
21 fn Prof => Prim.PROF
22 | Real => Prim.REAL
23 | Virtual => Prim.VIRTUAL
24
25 fun set' (t, {interval, value}) =
26 let
27 fun split t =
28 let
29 val q = LargeInt.quot (Time.toMicroseconds t, 1000000)
30 val r = LargeInt.rem (Time.toMicroseconds t, 1000000)
31 in
32 (C_Time.fromLargeInt q, C_SUSeconds.fromLargeInt r)
33 end
34 val (s1, u1) = split interval
35 val (s2, u2) = split value
36 in
37 ignore (Prim.set (toInt t, s1, u1, s2, u2))
38 end
39
40 fun set (z as (t, _)) =
41 if Primitive.MLton.Profile.isOn
42 andalso t = Prof
43 then let
44 open PosixError
45 in
46 raiseSys inval
47 end
48 else set' z
49 end