Skip to content

Commit 71988d3

Browse files
committed
Merge pull request #1279 from petermm/system.ex
System.ex monotonic_time/1 system_time/1 Carbon copy from elixir with :native time unit removed, as it's not supported by current erlang implementation. These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 678fcd8 + 03ee764 commit 71988d3

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

libs/exavmlib/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(ELIXIR_MODULES
4949
Process
5050
Protocol.UndefinedError
5151
Range
52+
System
5253
Tuple
5354

5455
ArithmeticError

libs/exavmlib/lib/System.ex

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# This file is part of elixir-lang.
3+
#
4+
# Copyright 2012-2024 Elixir Contributors
5+
# https://github.com/elixir-lang/elixir/blob/v1.17/lib/elixir/lib/system.ex
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# SPDX-License-Identifier: Apache-2.0
20+
#
21+
22+
defmodule System do
23+
@compile {:autoload, false}
24+
@type time_unit ::
25+
:second
26+
| :millisecond
27+
| :microsecond
28+
29+
@doc """
30+
Returns the current monotonic time in the given time unit.
31+
32+
This time is monotonically increasing and starts in an unspecified
33+
point in time.
34+
"""
35+
@spec monotonic_time(time_unit) :: integer
36+
def monotonic_time(unit) do
37+
:erlang.monotonic_time(unit)
38+
end
39+
40+
@doc """
41+
Returns the current system time in the given time unit.
42+
43+
It is the VM view of the `os_time/0`. They may not match in
44+
case of time warps although the VM works towards aligning
45+
them. This time is not monotonic.
46+
"""
47+
@spec system_time(time_unit) :: integer
48+
def system_time(unit) do
49+
:erlang.system_time(unit)
50+
end
51+
end

0 commit comments

Comments
 (0)