diff options
author | John Högberg <[email protected]> | 2019-01-09 14:24:02 +0100 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-01-09 14:24:02 +0100 |
commit | 09879be76191b0f3f76a80d3fd798bcd69961e2e (patch) | |
tree | 13909e3d561ca03a4189bd6265637d078aa12ba8 /erts/preloaded | |
parent | 648a86aa9c2df78501242d68c72fd5769f5d66c9 (diff) | |
parent | f28b2e471d81ec65a69e77d61909616482b256d0 (diff) | |
download | otp-09879be76191b0f3f76a80d3fd798bcd69961e2e.tar.gz otp-09879be76191b0f3f76a80d3fd798bcd69961e2e.tar.bz2 otp-09879be76191b0f3f76a80d3fd798bcd69961e2e.zip |
Merge branch 'maint'
* maint:
Remove an unused variable
Spawn prim_file helper as a system process
Diffstat (limited to 'erts/preloaded')
-rw-r--r-- | erts/preloaded/ebin/erts_internal.beam | bin | 17576 -> 17800 bytes | |||
-rw-r--r-- | erts/preloaded/ebin/prim_file.beam | bin | 28256 -> 28088 bytes | |||
-rw-r--r-- | erts/preloaded/src/erts_internal.erl | 9 | ||||
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 23 |
4 files changed, 20 insertions, 12 deletions
diff --git a/erts/preloaded/ebin/erts_internal.beam b/erts/preloaded/ebin/erts_internal.beam Binary files differindex 7ce8ed18f9..2e7f873426 100644 --- a/erts/preloaded/ebin/erts_internal.beam +++ b/erts/preloaded/ebin/erts_internal.beam diff --git a/erts/preloaded/ebin/prim_file.beam b/erts/preloaded/ebin/prim_file.beam Binary files differindex abd18c044b..49feb950a8 100644 --- a/erts/preloaded/ebin/prim_file.beam +++ b/erts/preloaded/ebin/prim_file.beam diff --git a/erts/preloaded/src/erts_internal.erl b/erts/preloaded/src/erts_internal.erl index 8f29a569f2..305b524438 100644 --- a/erts/preloaded/src/erts_internal.erl +++ b/erts/preloaded/src/erts_internal.erl @@ -97,6 +97,8 @@ -export([counters_new/1, counters_get/2, counters_add/3, counters_put/3, counters_info/1]). +-export([spawn_system_process/3]). + %% %% Await result of send to port %% @@ -726,3 +728,10 @@ counters_put(_Ref, _Ix, _Value) -> -spec counters_info(reference()) -> #{}. counters_info(_Ref) -> erlang:nif_error(undef). + +-spec spawn_system_process(Mod, Func, Args) -> pid() when + Mod :: atom(), + Func :: atom(), + Args :: list(). +spawn_system_process(_Mod, _Func, _Args) -> + erlang:nif_error(undefined). diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 5fc22bc582..0994e2a9f4 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -46,7 +46,7 @@ -define(MIN_READLINE_SIZE, 256). -define(LARGEFILESIZE, (1 bsl 63)). --export([copy/3]). +-export([copy/3, start/0]). -include("file_int.hrl"). @@ -85,14 +85,21 @@ is_translatable(_) -> %% This is a janitor process used to close files whose controlling process has %% died. The emulator will be torn down if this is killed. -delayed_close_loop() -> +start() -> + helper_loop(). + +helper_loop() -> receive {close, FRef} when is_reference(FRef) -> delayed_close_nif(FRef); _ -> ok end, - delayed_close_loop(). + helper_loop(). -%% +on_load() -> + %% This is spawned as a system process to prevent init:restart/0 from + %% killing it. + Pid = erts_internal:spawn_system_process(?MODULE, start, []), + ok = erlang:load_nif(atom_to_list(?MODULE), Pid). %% Returns {error, Reason} | {ok, BytesCopied} copy(#file_descriptor{module = ?MODULE} = Source, @@ -103,14 +110,6 @@ copy(#file_descriptor{module = ?MODULE} = Source, %% XXX Should be moved down to the driver for optimization. file:copy_opened(Source, Dest, Length). -on_load() -> - Pid = spawn(fun() -> - process_flag(trap_exit, true), - delayed_close_loop() - end), - true = register(erts_prim_file, Pid), - ok = erlang:load_nif(atom_to_list(?MODULE), Pid). - open(Name, Modes) -> %% The try/catch pattern seen here is used throughout the file to adhere to %% the public file interface, which has leaked through for ages because of |