aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/erts_internal.erl
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-01-12 17:02:06 +0100
committerSverker Eriksson <[email protected]>2016-01-13 19:59:54 +0100
commita4920dc4045f394f6f4ab1cc89d54d55722a66d6 (patch)
tree56b574449f8eb50a624492f7558bd6eec53b45b5 /erts/preloaded/src/erts_internal.erl
parent79efde2d8503e5055ef9e8afa5d8d63208710b1f (diff)
downloadotp-a4920dc4045f394f6f4ab1cc89d54d55722a66d6.tar.gz
otp-a4920dc4045f394f6f4ab1cc89d54d55722a66d6.tar.bz2
otp-a4920dc4045f394f6f4ab1cc89d54d55722a66d6.zip
erts: Refactor check_process_code/3
Move impl from erlang to erts_internal. Cut and paste.
Diffstat (limited to 'erts/preloaded/src/erts_internal.erl')
-rw-r--r--erts/preloaded/src/erts_internal.erl55
1 files changed, 54 insertions, 1 deletions
diff --git a/erts/preloaded/src/erts_internal.erl b/erts/preloaded/src/erts_internal.erl
index 30e9ba304c..e32d65ff59 100644
--- a/erts/preloaded/src/erts_internal.erl
+++ b/erts/preloaded/src/erts_internal.erl
@@ -37,7 +37,7 @@
-export([request_system_task/3]).
--export([check_process_code/2]).
+-export([check_process_code/3]).
-export([copy_literals/2]).
-export([purge_module/1]).
@@ -49,6 +49,9 @@
-export([is_system_process/1]).
+%% Auto import name clash
+-export([check_process_code/2]).
+
%%
%% Await result of send to port
%%
@@ -206,6 +209,56 @@ request_system_task(_Pid, _Prio, _Request) ->
check_process_code(_Module, _OptionList) ->
erlang:nif_error(undefined).
+-spec check_process_code(Pid, Module, OptionList) -> CheckResult | async when
+ Pid :: pid(),
+ Module :: module(),
+ RequestId :: term(),
+ Option :: {async, RequestId} | {allow_gc, boolean()},
+ OptionList :: [Option],
+ CheckResult :: boolean() | aborted.
+check_process_code(Pid, Module, OptionList) ->
+ {Async, AllowGC} = get_cpc_opts(OptionList, sync, true),
+ case Async of
+ {async, ReqId} ->
+ {priority, Prio} = erlang:process_info(erlang:self(),
+ priority),
+ erts_internal:request_system_task(Pid,
+ Prio,
+ {check_process_code,
+ ReqId,
+ Module,
+ AllowGC}),
+ async;
+ sync ->
+ case Pid == erlang:self() of
+ true ->
+ erts_internal:check_process_code(Module,
+ [{allow_gc, AllowGC}]);
+ false ->
+ {priority, Prio} = erlang:process_info(erlang:self(),
+ priority),
+ ReqId = erlang:make_ref(),
+ erts_internal:request_system_task(Pid,
+ Prio,
+ {check_process_code,
+ ReqId,
+ Module,
+ AllowGC}),
+ receive
+ {check_process_code, ReqId, CheckResult} ->
+ CheckResult
+ end
+ end
+ end.
+
+% gets async and allow_gc opts and verify valid option list
+get_cpc_opts([{async, _ReqId} = AsyncTuple | Options], _OldAsync, AllowGC) ->
+ get_cpc_opts(Options, AsyncTuple, AllowGC);
+get_cpc_opts([{allow_gc, AllowGC} | Options], Async, _OldAllowGC) ->
+ get_cpc_opts(Options, Async, AllowGC);
+get_cpc_opts([], Async, AllowGC) ->
+ {Async, AllowGC}.
+
-spec copy_literals(Module,Bool) -> 'true' | 'false' | 'aborted' when
Module :: module(),
Bool :: boolean().