aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-08-25 09:29:41 +0200
committerBjörn Gustavsson <[email protected]>2011-08-26 11:37:17 +0200
commit4275ca6ecfa35554416bdb517999642b242e9776 (patch)
tree659895bb3f9d5947646c0305e516fdb04aaa53f5 /lib/kernel
parent631939c2452413014dfe3777997157ab541770ae (diff)
downloadotp-4275ca6ecfa35554416bdb517999642b242e9776.tar.gz
otp-4275ca6ecfa35554416bdb517999642b242e9776.tar.bz2
otp-4275ca6ecfa35554416bdb517999642b242e9776.zip
code: Optimize purge/1 and soft_purge/1 using check_old_code/1
While at it, eliminate an unnecessary use of throw/catch in the implementation of soft_purge/1.
Diffstat (limited to 'lib/kernel')
-rw-r--r--lib/kernel/src/code_server.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index 4a1fc7df34..85bbff9cc3 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -1379,8 +1379,12 @@ absname_vr([[X, $:]|Name], _, _AbsBase) ->
%% Kill all processes running code from *old* Module, and then purge the
%% module. Return true if any processes killed, else false.
-do_purge(Mod) ->
- do_purge(processes(), to_atom(Mod), false).
+do_purge(Mod0) ->
+ Mod = to_atom(Mod0),
+ case erlang:check_old_code(Mod) of
+ false -> false;
+ true -> do_purge(processes(), Mod, false)
+ end.
do_purge([P|Ps], Mod, Purged) ->
case erlang:check_process_code(P, Mod) of
@@ -1399,16 +1403,19 @@ do_purge([], Mod, Purged) ->
Purged.
%% do_soft_purge(Module)
-%% Purge old code only if no procs remain that run old code
+%% Purge old code only if no procs remain that run old code.
%% Return true in that case, false if procs remain (in this
%% case old code is not purged)
do_soft_purge(Mod) ->
- catch do_soft_purge(processes(), Mod).
+ case erlang:check_old_code(Mod) of
+ false -> true;
+ true -> do_soft_purge(processes(), Mod)
+ end.
do_soft_purge([P|Ps], Mod) ->
case erlang:check_process_code(P, Mod) of
- true -> throw(false);
+ true -> false;
false -> do_soft_purge(Ps, Mod)
end;
do_soft_purge([], Mod) ->