aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'lib/diameter/src/base')
-rw-r--r--lib/diameter/src/base/diameter_config.erl3
-rw-r--r--lib/diameter/src/base/diameter_lib.erl101
-rw-r--r--lib/diameter/src/base/diameter_peer.erl3
-rw-r--r--lib/diameter/src/base/diameter_reg.erl3
-rw-r--r--lib/diameter/src/base/diameter_service.erl5
-rw-r--r--lib/diameter/src/base/diameter_session.erl4
-rw-r--r--lib/diameter/src/base/diameter_stats.erl3
-rw-r--r--lib/diameter/src/base/diameter_sync.erl3
-rw-r--r--lib/diameter/src/base/diameter_watchdog.erl8
9 files changed, 11 insertions, 122 deletions
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl
index 8ac3b9d6ca..89b26707ad 100644
--- a/lib/diameter/src/base/diameter_config.erl
+++ b/lib/diameter/src/base/diameter_config.erl
@@ -37,8 +37,7 @@
-module(diameter_config).
-behaviour(gen_server).
--compile({no_auto_import, [monitor/2, now/0]}).
--import(diameter_lib, [now/0]).
+-compile({no_auto_import, [monitor/2]}).
-export([start_service/2,
stop_service/1,
diff --git a/lib/diameter/src/base/diameter_lib.erl b/lib/diameter/src/base/diameter_lib.erl
index b9b3e21788..26cc6137a2 100644
--- a/lib/diameter/src/base/diameter_lib.erl
+++ b/lib/diameter/src/base/diameter_lib.erl
@@ -18,18 +18,12 @@
%%
-module(diameter_lib).
--compile({no_auto_import, [now/0]}).
-export([info_report/2,
error_report/2,
warning_report/2,
- now/0,
- timestamp/1,
now_diff/1,
- micro_diff/1,
- micro_diff/2,
time/1,
- seed/0,
eval/1,
eval_name/1,
get_stacktrace/0,
@@ -98,49 +92,10 @@ fmt(T) ->
end.
%% ---------------------------------------------------------------------------
-%% # now/0
-%% ---------------------------------------------------------------------------
-
--type timestamp() :: {non_neg_integer(), 0..999999, 0..999999}.
--type now() :: integer() %% monotonic time
- | timestamp().
-
--spec now()
- -> now().
-
-%% Use monotonic time if it exists, fall back to erlang:now()
-%% otherwise.
-
-now() ->
- try
- erlang:monotonic_time()
- catch
- error: undef -> erlang:now()
- end.
-
-%% ---------------------------------------------------------------------------
-%% # timestamp/1
-%% ---------------------------------------------------------------------------
-
--spec timestamp(NowT :: now())
- -> timestamp().
-
-timestamp({_,_,_} = T) -> %% erlang:now()
- T;
-
-timestamp(MonoT) -> %% monotonic time
- MicroSecs = monotonic_to_microseconds(MonoT + erlang:time_offset()),
- Secs = MicroSecs div 1000000,
- {Secs div 1000000, Secs rem 1000000, MicroSecs rem 1000000}.
-
-monotonic_to_microseconds(MonoT) ->
- erlang:convert_time_unit(MonoT, native, micro_seconds).
-
-%% ---------------------------------------------------------------------------
%% # now_diff/1
%% ---------------------------------------------------------------------------
--spec now_diff(NowT :: now())
+-spec now_diff(NowT :: erlang:timestamp())
-> {Hours, Mins, Secs, MicroSecs}
when Hours :: non_neg_integer(),
Mins :: 0..59,
@@ -151,36 +106,7 @@ monotonic_to_microseconds(MonoT) ->
%% instead of as integer microseconds.
now_diff(Time) ->
- time(micro_diff(Time)).
-
-%% ---------------------------------------------------------------------------
-%% # micro_diff/1
-%% ---------------------------------------------------------------------------
-
--spec micro_diff(NowT :: now())
- -> MicroSecs
- when MicroSecs :: non_neg_integer().
-
-micro_diff({_,_,_} = T0) ->
- timer:now_diff(erlang:now(), T0);
-
-micro_diff(T0) -> %% monotonic time
- monotonic_to_microseconds(erlang:monotonic_time() - T0).
-
-%% ---------------------------------------------------------------------------
-%% # micro_diff/2
-%% ---------------------------------------------------------------------------
-
--spec micro_diff(T1 :: now(), T0 :: now())
- -> MicroSecs
- when MicroSecs :: non_neg_integer().
-
-micro_diff(T1, T0)
- when is_integer(T1), is_integer(T0) -> %% monotonic time
- monotonic_to_microseconds(T1 - T0);
-
-micro_diff(T1, T0) -> %% at least one erlang:now()
- timer:now_diff(timestamp(T1), timestamp(T0)).
+ time(timer:now_diff(now(), Time)).
%% ---------------------------------------------------------------------------
%% # time/1
@@ -190,7 +116,7 @@ micro_diff(T1, T0) -> %% at least one erlang:now()
-spec time(NowT | Diff)
-> {Hours, Mins, Secs, MicroSecs}
- when NowT :: timestamp(),
+ when NowT :: erlang:timestamp(),
Diff :: non_neg_integer(),
Hours :: non_neg_integer(),
Mins :: 0..59,
@@ -209,27 +135,6 @@ time(Micro) -> %% elapsed time
{H, M, S, Micro rem 1000000}.
%% ---------------------------------------------------------------------------
-%% # seed/0
-%% ---------------------------------------------------------------------------
-
--spec seed()
- -> {timestamp(), {integer(), integer(), integer()}}.
-
-%% Return an argument for random:seed/1.
-
-seed() ->
- T = now(),
- {timestamp(T), seed(T)}.
-
-%% seed/1
-
-seed({_,_,_} = T) ->
- T;
-
-seed(T) -> %% monotonic time
- {erlang:phash2(node()), T, erlang:unique_integer()}.
-
-%% ---------------------------------------------------------------------------
%% # eval/1
%%
%% Evaluate a function in various forms.
diff --git a/lib/diameter/src/base/diameter_peer.erl b/lib/diameter/src/base/diameter_peer.erl
index b31aa65ce3..1ae8b567b1 100644
--- a/lib/diameter/src/base/diameter_peer.erl
+++ b/lib/diameter/src/base/diameter_peer.erl
@@ -20,9 +20,6 @@
-module(diameter_peer).
-behaviour(gen_server).
--compile({no_auto_import, [now/0]}).
--import(diameter_lib, [now/0]).
-
%% Interface towards transport modules ...
-export([recv/2,
up/1,
diff --git a/lib/diameter/src/base/diameter_reg.erl b/lib/diameter/src/base/diameter_reg.erl
index f785777874..6bb4710e63 100644
--- a/lib/diameter/src/base/diameter_reg.erl
+++ b/lib/diameter/src/base/diameter_reg.erl
@@ -24,8 +24,7 @@
-module(diameter_reg).
-behaviour(gen_server).
--compile({no_auto_import, [monitor/2, now/0]}).
--import(diameter_lib, [now/0]).
+-compile({no_auto_import, [monitor/2]}).
-export([add/1,
add_new/1,
diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl
index 86e744dfbe..a31cef2c8c 100644
--- a/lib/diameter/src/base/diameter_service.erl
+++ b/lib/diameter/src/base/diameter_service.erl
@@ -24,9 +24,6 @@
-module(diameter_service).
-behaviour(gen_server).
--compile({no_auto_import, [now/0]}).
--import(diameter_lib, [now/0]).
-
%% towards diameter_service_sup
-export([start_link/1]).
@@ -1218,7 +1215,7 @@ connect_timer(Opts, Def0) ->
%% continuous restarted in case of faulty config or other problems.
tc(Time, Tc) ->
choose(Tc > ?RESTART_TC
- orelse diameter_lib:micro_diff(Time) > 1000*?RESTART_TC,
+ orelse timer:now_diff(now(), Time) > 1000*?RESTART_TC,
Tc,
?RESTART_TC).
diff --git a/lib/diameter/src/base/diameter_session.erl b/lib/diameter/src/base/diameter_session.erl
index c5ea0428b5..3b236f109a 100644
--- a/lib/diameter/src/base/diameter_session.erl
+++ b/lib/diameter/src/base/diameter_session.erl
@@ -157,8 +157,8 @@ session_id(Host) ->
%% ---------------------------------------------------------------------------
init() ->
- {Now, Seed} = diameter_lib:seed(),
- random:seed(Seed),
+ Now = now(),
+ random:seed(Now),
Time = time32(Now),
Seq = (?INT32 band (Time bsl 20)) bor (random:uniform(1 bsl 20) - 1),
ets:insert(diameter_sequence, [{origin_state_id, Time},
diff --git a/lib/diameter/src/base/diameter_stats.erl b/lib/diameter/src/base/diameter_stats.erl
index 79a5c7b947..c4526d3a08 100644
--- a/lib/diameter/src/base/diameter_stats.erl
+++ b/lib/diameter/src/base/diameter_stats.erl
@@ -24,9 +24,6 @@
-module(diameter_stats).
-behaviour(gen_server).
--compile({no_auto_import, [now/0]}).
--import(diameter_lib, [now/0]).
-
-export([reg/2, reg/1,
incr/3, incr/1,
read/1,
diff --git a/lib/diameter/src/base/diameter_sync.erl b/lib/diameter/src/base/diameter_sync.erl
index 90eabece3d..cee06b9e96 100644
--- a/lib/diameter/src/base/diameter_sync.erl
+++ b/lib/diameter/src/base/diameter_sync.erl
@@ -27,9 +27,6 @@
-module(diameter_sync).
-behaviour(gen_server).
--compile({no_auto_import, [now/0]}).
--import(diameter_lib, [now/0]).
-
-export([call/4, call/5,
cast/4, cast/5,
carp/1, carp/2]).
diff --git a/lib/diameter/src/base/diameter_watchdog.erl b/lib/diameter/src/base/diameter_watchdog.erl
index ac03ab1260..885dc6c801 100644
--- a/lib/diameter/src/base/diameter_watchdog.erl
+++ b/lib/diameter/src/base/diameter_watchdog.erl
@@ -66,7 +66,6 @@
parent = self() :: pid(), %% service process
transport :: pid() | undefined, %% peer_fsm process
tref :: reference() %% reference for current watchdog timer
- | integer() %% monotonic time
| tuple() %% now()
| undefined,
dictionary :: module(), %% common dictionary
@@ -125,8 +124,7 @@ i({Ack, T, Pid, {RecvData,
= Svc}}) ->
monitor(process, Pid),
wait(Ack, Pid),
- {_, Seed} = diameter_lib:seed(),
- random:seed(Seed),
+ random:seed(now()),
putr(restart, {T, Opts, Svc, SvcOpts}), %% save seeing it in trace
putr(dwr, dwr(Caps)), %%
{_,_} = Mask = proplists:get_value(sequence, SvcOpts),
@@ -459,7 +457,7 @@ transition({timeout, TRef, tw}, #watchdog{tref = TRef} = S) ->
%% Message has arrived since the timer was started: subtract time
%% already elapsed from new timer.
transition({timeout, _, tw}, #watchdog{tref = T0} = S) ->
- set_watchdog(diameter_lib:micro_diff(T0) div 1000, S);
+ set_watchdog(timer:now_diff(now(), T0) div 1000, S);
%% State query.
transition({state, Pid}, #watchdog{status = S}) ->
@@ -541,7 +539,7 @@ set_watchdog(#watchdog{tref = undefined} = S) ->
%% Timer already set: start at new one only at expiry.
set_watchdog(#watchdog{} = S) ->
- S#watchdog{tref = diameter_lib:now()};
+ S#watchdog{tref = now()};
set_watchdog(stop = No) ->
No.