diff options
author | Fredrik Gustafsson <[email protected]> | 2013-04-11 17:46:24 +0200 |
---|---|---|
committer | Fredrik Gustafsson <[email protected]> | 2013-04-11 17:46:24 +0200 |
commit | b517a3a6c8d142a813c4e082eb220ec04da00dde (patch) | |
tree | 831a4b1b2ca94e82c1163f110b2acdb554f33afd /lib | |
parent | 8bb22100b1b12eca0f6953cac031c8f780988c16 (diff) | |
parent | e09920ed1da9ebf3efa814d8f5039140109beab3 (diff) | |
download | otp-b517a3a6c8d142a813c4e082eb220ec04da00dde.tar.gz otp-b517a3a6c8d142a813c4e082eb220ec04da00dde.tar.bz2 otp-b517a3a6c8d142a813c4e082eb220ec04da00dde.zip |
Merge branch 'maint'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdlib/src/gen.erl | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/stdlib/src/gen.erl b/lib/stdlib/src/gen.erl index 42555aedd7..5df5530ba1 100644 --- a/lib/stdlib/src/gen.erl +++ b/lib/stdlib/src/gen.erl @@ -17,6 +17,7 @@ %% %CopyrightEnd% %% -module(gen). +-compile({inline,[get_node/1]}). %%%----------------------------------------------------------------- %%% This module implements the really generic stuff of the generic @@ -194,16 +195,6 @@ call({_Name, Node}=Process, Label, Request, Timeout) end. do_call(Process, Label, Request, Timeout) -> - %% We trust the arguments to be correct, i.e - %% Process is either a local or remote pid, - %% or a {Name, Node} tuple (of atoms) and in this - %% case this node (node()) _is_ distributed and Node =/= node(). - Node = case Process of - {_S, N} when is_atom(N) -> - N; - _ when is_pid(Process) -> - node(Process) - end, try erlang:monitor(process, Process) of Mref -> %% If the monitor/2 call failed to set up a connection to a @@ -222,15 +213,12 @@ do_call(Process, Label, Request, Timeout) -> erlang:demonitor(Mref, [flush]), {ok, Reply}; {'DOWN', Mref, _, _, noconnection} -> + Node = get_node(Process), exit({nodedown, Node}); {'DOWN', Mref, _, _, Reason} -> exit(Reason) after Timeout -> - erlang:demonitor(Mref), - receive - {'DOWN', Mref, _, _, _} -> true - after 0 -> true - end, + erlang:demonitor(Mref, [flush]), exit(timeout) end catch @@ -241,6 +229,7 @@ do_call(Process, Label, Request, Timeout) -> %% Do the best possible with monitor_node/2. %% This code may hang indefinitely if the Process %% does not exist. It is only used for featureweak remote nodes. + Node = get_node(Process), monitor_node(Node, true), receive {nodedown, Node} -> @@ -253,6 +242,18 @@ do_call(Process, Label, Request, Timeout) -> end end. +get_node(Process) -> + %% We trust the arguments to be correct, i.e + %% Process is either a local or remote pid, + %% or a {Name, Node} tuple (of atoms) and in this + %% case this node (node()) _is_ distributed and Node =/= node(). + case Process of + {_S, N} when is_atom(N) -> + N; + _ when is_pid(Process) -> + node(Process) + end. + wait_resp(Node, Tag, Timeout) -> receive {Tag, Reply} -> |