From c5cbd8647bced5e90e249c173d5c92065eb7d68e Mon Sep 17 00:00:00 2001 From: Dmitry Russ Date: Thu, 16 Nov 2017 06:07:11 +0100 Subject: [PATCH] Fix crash by backwards-rolling time by otp_release > 18 Add define directive, which works with rebar3. Fixes #12. --- rebar.config | 4 ++++ src/locker.erl | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/rebar.config b/rebar.config index 2c94a40..997fc16 100644 --- a/rebar.config +++ b/rebar.config @@ -8,3 +8,7 @@ ]}. {ct_use_short_names, true}. + +{erl_opts, [ + {platform_define, "^(18|19|2)+", support_new_time_api} +]}. diff --git a/src/locker.erl b/src/locker.erl index 0e3fad2..8ca9f4b 100644 --- a/src/locker.erl +++ b/src/locker.erl @@ -638,6 +638,13 @@ notify_release_waiter(Key, Value, AllWaiters) -> lists:foreach(Reply, KeyWaiters), OtherWaiters. +-ifdef(support_new_time_api). +now_to_seconds() -> + erlang:monotonic_time(second). + +now_to_ms() -> + erlang:monotonic_time(millisecond). +-else. now_to_seconds() -> now_to_seconds(os:timestamp()). @@ -650,6 +657,7 @@ now_to_ms() -> now_to_ms({MegaSecs,Secs,MicroSecs}) -> (MegaSecs * 1000000 + Secs) * 1000 + MicroSecs div 1000. +-endif. ok_responses(Replies) -> lists:partition(fun ({_, ok}) -> true;