From 3e9c9fc750dff18d546e13c404402823eb490a5e Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 13 Dec 2010 12:17:28 +0100 Subject: [PATCH] Remove Type and Spec, backport list comprehensions, so R12B-5 can compile --- src/pg2_backport.erl | 56 +++++--------------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/src/pg2_backport.erl b/src/pg2_backport.erl index 9c9f5d6bc..f706e66a9 100644 --- a/src/pg2_backport.erl +++ b/src/pg2_backport.erl @@ -30,18 +30,12 @@ %%% Exported functions %%% --spec start_link() -> {'ok', pid()} | {'error', term()}. - start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). --spec start() -> {'ok', pid()} | {'error', term()}. - start() -> ensure_started(). --spec create(term()) -> 'ok'. - create(Name) -> ensure_started(), case ets:member(pg2_table, {group, Name}) of @@ -55,10 +49,6 @@ create(Name) -> ok end. --type name() :: term(). - --spec delete(name()) -> 'ok'. - delete(Name) -> ensure_started(), global:trans({{?MODULE, Name}, self()}, @@ -67,8 +57,6 @@ delete(Name) -> end), ok. --spec join(name(), pid()) -> 'ok' | {'error', {'no_such_group', term()}}. - join(Name, Pid) when is_pid(Pid) -> ensure_started(), case ets:member(pg2_table, {group, Name}) of @@ -83,8 +71,6 @@ join(Name, Pid) when is_pid(Pid) -> ok end. --spec leave(name(), pid()) -> 'ok' | {'error', {'no_such_group', name()}}. - leave(Name, Pid) when is_pid(Pid) -> ensure_started(), case ets:member(pg2_table, {group, Name}) of @@ -99,10 +85,6 @@ leave(Name, Pid) when is_pid(Pid) -> ok end. --type get_members_ret() :: [pid()] | {'error', {'no_such_group', name()}}. - --spec get_members(name()) -> get_members_ret(). - get_members(Name) -> ensure_started(), case ets:member(pg2_table, {group, Name}) of @@ -112,8 +94,6 @@ get_members(Name) -> {error, {no_such_group, Name}} end. --spec get_local_members(name()) -> get_members_ret(). - get_local_members(Name) -> ensure_started(), case ets:member(pg2_table, {group, Name}) of @@ -123,16 +103,10 @@ get_local_members(Name) -> {error, {no_such_group, Name}} end. --spec which_groups() -> [name()]. - which_groups() -> ensure_started(), all_groups(). --type gcp_error_reason() :: {'no_process', term()} | {'no_such_group', term()}. - --spec get_closest_pid(term()) -> pid() | {'error', gcp_error_reason()}. - get_closest_pid(Name) -> case get_local_members(Name) of [Pid] -> @@ -157,8 +131,6 @@ get_closest_pid(Name) -> -record(state, {}). --spec init([]) -> {'ok', #state{}}. - init([]) -> Ns = nodes(), net_kernel:monitor_nodes(true), @@ -169,14 +141,6 @@ init([]) -> pg2_table = ets:new(pg2_table, [ordered_set, protected, named_table]), {ok, #state{}}. --type call() :: {'create', name()} - | {'delete', name()} - | {'join', name(), pid()} - | {'leave', name(), pid()}. - --spec handle_call(call(), _, #state{}) -> - {'reply', 'ok', #state{}}. - handle_call({create, Name}, _From, S) -> assure_group(Name), {reply, ok, S}; @@ -195,12 +159,6 @@ handle_call(Request, From, S) -> [Request, From]), {noreply, S}. --type all_members() :: [[name(),...]]. --type cast() :: {'exchange', node(), all_members()} - | {'del_member', name(), pid()}. - --spec handle_cast(cast(), #state{}) -> {'noreply', #state{}}. - handle_cast({exchange, _Node, List}, S) -> store(List), {noreply, S}; @@ -208,8 +166,6 @@ handle_cast(_, S) -> %% Ignore {del_member, Name, Pid}. {noreply, S}. --spec handle_info(tuple(), #state{}) -> {'noreply', #state{}}. - handle_info({'DOWN', MonitorRef, process, _Pid, _Info}, S) -> member_died(MonitorRef), {noreply, S}; @@ -222,8 +178,6 @@ handle_info({new_pg2, Node}, S) -> handle_info(_, S) -> {noreply, S}. --spec terminate(term(), #state{}) -> 'ok'. - terminate(_Reason, _S) -> true = ets:delete(pg2_table), ok. @@ -289,8 +243,9 @@ join_group(Name, Pid) -> try _ = ets:update_counter(pg2_table, Member_Name_Pid, {2, +1}) catch _:_ -> true = ets:insert(pg2_table, {Member_Name_Pid, 1}), - _ = [ets:insert(pg2_table, {{local_member, Name, Pid}}) || - node(Pid) =:= node()], + _ = [ets:insert(pg2_table, {{local_member, Name, PidX}}) || + PidX <- [Pid], + node(PidX) =:= node()], true = ets:insert(pg2_table, {{pid, Pid, Name}}) end. @@ -301,8 +256,9 @@ leave_group(Name, Pid) -> if N =:= 0 -> true = ets:delete(pg2_table, {pid, Pid, Name}), - _ = [ets:delete(pg2_table, {local_member, Name, Pid}) || - node(Pid) =:= node()], + _ = [ets:delete(pg2_table, {local_member, Name, PidX}) || + PidX <- [Pid], + node(PidX) =:= node()], true = ets:delete(pg2_table, Member_Name_Pid); true -> ok