Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
2616-pg-ensure-argument-is-expected-local-pid-s...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2616-pg-ensure-argument-is-expected-local-pid-s.patch of Package erlang
From 096fa63c0a1295e8382726e95db886b3b453cea9 Mon Sep 17 00:00:00 2001 From: "Robert A. Nowak" <r.nowak@sciencia.se> Date: Thu, 13 Feb 2020 15:13:30 +0100 Subject: [PATCH] pg: ensure argument is expected local pid(s) Changes join/3 and leave/3 to ensure that the expected pid or list of pids argument is actually a local pid or list of such. --- lib/kernel/src/pg.erl | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/kernel/src/pg.erl b/lib/kernel/src/pg.erl index 0668dd1f79..9b236d3187 100644 --- a/lib/kernel/src/pg.erl +++ b/lib/kernel/src/pg.erl @@ -117,31 +117,29 @@ start_link(Scope) when is_atom(Scope) -> %%-------------------------------------------------------------------- %% @doc -%% Joins a single process +%% Joins a single or a list of processes. %% Group is created automatically. -%% Process must be local to this node. +%% Processes must be local to this node. -spec join(Group :: group(), PidOrPids :: pid() | [pid()]) -> ok. join(Group, PidOrPids) -> join(?DEFAULT_SCOPE, Group, PidOrPids). -spec join(Scope :: atom(), Group :: group(), PidOrPids :: pid() | [pid()]) -> ok. -join(Scope, Group, PidOrPids) -> - Node = node(), - is_list(PidOrPids) andalso [error({nolocal, Pid}) || Pid <- PidOrPids, node(Pid) =/= Node orelse not is_pid(Pid)], +join(Scope, Group, PidOrPids) when is_pid(PidOrPids); is_list(PidOrPids) -> + ok = ensure_local(PidOrPids), gen_server:call(Scope, {join_local, Group, PidOrPids}, infinity). %%-------------------------------------------------------------------- %% @doc -%% Single process leaving the group. -%% Process must be local to this node. +%% Single or list of processes leaving the group. +%% Processes must be local to this node. -spec leave(Group :: group(), PidOrPids :: pid() | [pid()]) -> ok. leave(Group, PidOrPids) -> leave(?DEFAULT_SCOPE, Group, PidOrPids). --spec leave(Scope :: atom(), Group :: group(), Pid :: pid() | [pid()]) -> ok | not_joined. -leave(Scope, Group, PidOrPids) -> - Node = node(), - is_list(PidOrPids) andalso [error({nolocal, Pid}) || Pid <- PidOrPids, node(Pid) =/= Node orelse not is_pid(Pid)], +-spec leave(Scope :: atom(), Group :: group(), PidOrPids :: pid() | [pid()]) -> ok | not_joined. +leave(Scope, Group, PidOrPids) when is_pid(PidOrPids); is_list(PidOrPids) -> + ok = ensure_local(PidOrPids), gen_server:call(Scope, {leave_local, Group, PidOrPids}, infinity). %%-------------------------------------------------------------------- @@ -340,6 +338,20 @@ terminate(_Reason, #state{scope = Scope}) -> %%-------------------------------------------------------------------- %% Internal implementation +%% Ensures argument is either a node-local pid or a list of such, or it throws an error +ensure_local(Pid) when is_pid(Pid), node(Pid) =:= node() -> + ok; +ensure_local(Pids) when is_list(Pids) -> + lists:foreach( + fun + (Pid) when is_pid(Pid), node(Pid) =:= node() -> + ok; + (Bad) -> + error({nolocal, Bad}) + end, Pids); +ensure_local(Bad) -> + error({nolocal, Bad}). + %% Override all knowledge of the remote node with information it sends %% to local node. Current implementation must do the full table scan %% to remove stale pids (just as for 'nodedown'). -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor