aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMickael Remond <mremond@process-one.net>2016-07-26 12:12:48 +0200
committerMickael Remond <mremond@process-one.net>2016-07-26 12:12:48 +0200
commite5fd1ee4f6d80c464297eb9c7ae1c87c8b992e41 (patch)
tree83decff3fe3675cbb77f2fee9bea429edad8c238
parentMake jlib ETS table more resilient (diff)
Avoid starting several time the owner process
-rw-r--r--src/jid.erl15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/jid.erl b/src/jid.erl
index 46830d031..a730bd949 100644
--- a/src/jid.erl
+++ b/src/jid.erl
@@ -50,7 +50,7 @@
-spec start() -> ok.
start() ->
- Owner = spawn(fun() -> ets_keepalive() end),
+ {ok, Owner} = ets_owner(),
SplitPattern = binary:compile_pattern([<<"@">>, <<"/">>]),
%% Table is public to allow ETS insert to fix / update the table even if table already exist
%% with another owner.
@@ -58,6 +58,19 @@ start() ->
ets:insert(jlib, {string_to_jid_pattern, SplitPattern}),
ok.
+ets_owner() ->
+ case whereis(jlib_ets) of
+ undefined ->
+ Pid = spawn(fun() -> ets_keepalive() end),
+ case catch register(jlib_ets, Pid) of
+ true ->
+ {ok, Pid};
+ Error -> Error
+ end;
+ Pid ->
+ {ok,Pid}
+ end.
+
%% Process used to keep jlib ETS table alive in case the original owner dies.
%% The table need to be public, otherwise subsequent inserts would fail.
ets_keepalive() ->