Browse Source

Make compatible with Erlang 22.3.

Roberto Ostinelli 3 years ago
parent
commit
8c723a7cc5
4 changed files with 22 additions and 20 deletions
  1. 13 11
      src/syn_backbone.erl
  2. 6 6
      src/syn_gen_scope.erl
  3. 1 1
      test/syn_benchmark.erl
  4. 2 2
      test/syn_test_suite_helper.erl

+ 13 - 11
src/syn_backbone.erl

@@ -35,6 +35,12 @@
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
 
+- if (?OTP_RELEASE >= 23).
+-define(ETS_OPTIMIZATIONS, [{decentralized_counters, true}]).
+-else.
+-define(ETS_OPTIMIZATIONS, []).
+-endif.
+
 %% includes
 -include("syn.hrl").
 
@@ -82,8 +88,8 @@ get_table_name(TableId, Scope) ->
     {stop, Reason :: term()}.
 init([]) ->
     %% create table names table
-    ets:new(syn_table_names, [set, public, named_table, {read_concurrency, true}, {decentralized_counters, true}]),
-    ets:new(syn_process_names, [set, public, named_table, {read_concurrency, true}, {decentralized_counters, true}]),
+    ets:new(syn_table_names, [set, public, named_table, {read_concurrency, true}] ++ ?ETS_OPTIMIZATIONS),
+    ets:new(syn_process_names, [set, public, named_table, {read_concurrency, true}] ++ ?ETS_OPTIMIZATIONS),
     %% init
     {ok, #{}}.
 
@@ -150,23 +156,19 @@ code_change(_OldVsn, State, _Extra) ->
 %% ===================================================================
 %% Internal
 %% ===================================================================
--spec ensure_table_existence(Type :: ets:type(), TableId :: atom(), Scope :: atom()) -> ok.
+-spec ensure_table_existence(Type :: ets:type(), TableId :: atom(), Scope :: atom()) -> any().
 ensure_table_existence(Type, TableId, Scope) ->
     %% build name
-    TableIdBin = atom_to_binary(TableId),
-    ScopeBin = atom_to_binary(Scope),
-    TableName = binary_to_atom(<<TableIdBin/binary, "_", ScopeBin/binary>>),
+    TableIdBin = list_to_binary(atom_to_list(TableId)),
+    ScopeBin = list_to_binary(atom_to_list(Scope)),
+    TableName = list_to_atom(binary_to_list(<<TableIdBin/binary, "_", ScopeBin/binary>>)),
     %% save to loopkup table
     true = ets:insert(syn_table_names, {{TableId, Scope}, TableName}),
     %% check or create
     case ets:whereis(TableName) of
         undefined ->
             %% regarding decentralized_counters: <https://blog.erlang.org/scalable-ets-counters/>
-            ets:new(TableName, [
-                Type, public, named_table,
-                {read_concurrency, true}, {decentralized_counters, true}
-            ]),
-            ok;
+            ets:new(TableName, [Type, public, named_table, {read_concurrency, true}] ++ ?ETS_OPTIMIZATIONS);
 
         _ ->
             ok

+ 6 - 6
src/syn_gen_scope.erl

@@ -81,9 +81,9 @@
     {ok, Pid :: pid()} | {error, {already_started, Pid :: pid()}} | {error, Reason :: term()}.
 start_link(Handler, Scope) when is_atom(Scope) ->
     %% build name
-    HandlerBin = atom_to_binary(Handler),
-    ScopeBin = atom_to_binary(Scope),
-    ProcessName = binary_to_atom(<<HandlerBin/binary, "_", ScopeBin/binary>>),
+    HandlerBin = list_to_binary(atom_to_list(Handler)),
+    ScopeBin = list_to_binary(atom_to_list(Scope)),
+    ProcessName = list_to_atom(binary_to_list(<<HandlerBin/binary, "_", ScopeBin/binary>>)),
     %% save to lookup table
     syn_backbone:save_process_name({Handler, Scope}, ProcessName),
     %% create process
@@ -143,9 +143,9 @@ init([Handler, Scope, ProcessName]) ->
     %% start multicast process
     MulticastPid = spawn_link(?MODULE, multicast_loop, []),
     %% table names
-    HandlerBin = atom_to_binary(Handler),
-    TableByName = syn_backbone:get_table_name(binary_to_atom(<<HandlerBin/binary, "_by_name">>), Scope),
-    TableByPid = syn_backbone:get_table_name(binary_to_atom(<<HandlerBin/binary, "_by_pid">>), Scope),
+    HandlerBin = list_to_binary(atom_to_list(Handler)),
+    TableByName = syn_backbone:get_table_name(list_to_atom(binary_to_list(<<HandlerBin/binary, "_by_name">>)), Scope),
+    TableByPid = syn_backbone:get_table_name(list_to_atom(binary_to_list(<<HandlerBin/binary, "_by_pid">>)), Scope),
     %% build state
     State = #state{
         handler = Handler,

+ 1 - 1
test/syn_benchmark.erl

@@ -72,7 +72,7 @@ start() ->
     NodesInfo = lists:foldl(fun(I, Acc) ->
         %% start slave
         CountBin = integer_to_binary(I),
-        NodeShortName = binary_to_atom(<<"slave_", CountBin/binary>>),
+        NodeShortName = list_to_atom(binary_to_list(<<"slave_", CountBin/binary>>)),
         {ok, Node} = ct_slave:start(NodeShortName, [
             {boot_timeout, 10},
             {monitor_master, true}

+ 2 - 2
test/syn_test_suite_helper.erl

@@ -55,7 +55,7 @@ init_cluster(NodesCount) ->
     SlavesCount = NodesCount - 1,
     {Nodes, NodesConfig} = lists:foldl(fun(I, {AccNodes, AccNodesConfig}) ->
         IBin = integer_to_binary(I),
-        NodeShortName = binary_to_atom(<<"syn_slave_", IBin/binary>>),
+        NodeShortName = list_to_atom(binary_to_list(<<"syn_slave_", IBin/binary>>)),
         {ok, SlaveNode} = start_slave(NodeShortName),
         %% connect
         lists:foreach(fun(N) ->
@@ -83,7 +83,7 @@ end_cluster(NodesCount, Config) ->
     %% shutdown
     lists:foreach(fun(I) ->
         IBin = integer_to_binary(I),
-        NodeShortName = binary_to_atom(<<"syn_slave_", IBin/binary>>),
+        NodeShortName = list_to_atom(binary_to_list(<<"syn_slave_", IBin/binary>>)),
         SlaveNode = proplists:get_value(NodeShortName, Config),
         connect_node(SlaveNode),
         stop_slave(NodeShortName)