Переглянути джерело

Fix errors, detect persistent_term in a new way

pull/491/head
Andrew Thompson 5 роки тому
джерело
коміт
ea89ecc93e
2 змінених файлів з 45 додано та 32 видалено
  1. +14
    -2
      rebar.config.script
  2. +31
    -30
      src/lager_config.erl

+ 14
- 2
rebar.config.script Переглянути файл

@ -1,10 +1,22 @@
ExistingErlOpts = proplists:get_value(erl_opts, CONFIG, []),
CONFIG1 = case code:which(persistent_term) of
preloaded ->
lists:keyreplace(erl_opts, 1, CONFIG, {erl_opts, [{d, 'HAVE_PERSISTENT_TERM'}|ExistingErlOpts]});
non_existing ->
CONFIG
end,
case erlang:function_exported(rebar3, main, 1) of
true -> % rebar3
CONFIG;
CONFIG1;
false -> % rebar 2.x or older
%% Rebuild deps, possibly including those that have been moved to
%% profiles
[{deps, [
{goldrush, ".*", {git, "https://github.com/DeadZen/goldrush.git", {tag, "0.1.9"}}}
]} | lists:keydelete(deps, 1, CONFIG)]
]} | lists:keydelete(deps, 1, CONFIG1)]
end.

+ 31
- 30
src/lager_config.erl Переглянути файл

@ -73,7 +73,35 @@ set(Key, Value) ->
%% persistent term was added in OTP 21.2 but we can't
%% check minor versions with macros so we're stuck waiting
%% for OTP 22
-if(?OTP_RELEASE < 22).
-ifdef(HAVE_PERSISTENT_TERM).
init() ->
ok.
insert(Key, Value) ->
persistent_term:put({?TBL, Key}, Value).
insert_new(Key, Value) ->
try persistent_term:get({?TBL, Key}) of
_Value ->
false
catch error:badarg ->
insert(Key, Value),
true
end.
lookup(Key, Default) ->
try persistent_term:get({?TBL, Key}) of
Value -> Value
catch
error:badarg ->
Default
end.
cleanup() ->
[ persistent_term:erase(K) || {{?TBL, _} = K, _} <- persistent_term:get() ].
-else.
init() ->
%% set up the ETS configuration table
_ = try ets:new(?TBL, [named_table, public, set, {keypos, 1}, {read_concurrency, true}]) of
@ -85,10 +113,10 @@ init() ->
end.
insert(Key, Value) ->
ets:insert(?TBL, {{Sink, Key}, Value}).
ets:insert(?TBL, {Key, Value}).
insert_new(Key, Value) ->
ets:insert_new(?TBL, Key, Value).
ets:insert_new(?TBL, {Key, Value}).
lookup(Key, Default) ->
try
@ -104,32 +132,5 @@ lookup(Key, Default) ->
end.
cleanup() -> ok.
-else.
init() -> ok.
insert(Key, Value) ->
persistent_term:put({?TBL, Key}, Value).
insert_new(Key, Value) ->
try persistent_term:get({?TBL, Key}) of
_Value ->
false
catch error:badarg ->
insert(Key, Value),
true
end.
lookup(Key, Default) ->
try persistent_term:get({?TBL, Key}) of
Value -> Value
catch
error:badarg ->
Default
end.
cleanup() ->
[ persistent_term:erase(K) || {{?TBL, _} = K, _} <- persistent_term:get() ].
-endif.

Завантаження…
Відмінити
Зберегти