Skip to content

Commit

Permalink
Merge branch 'ks/erts' into ccase/r13b04_dev
Browse files Browse the repository at this point in the history
* ks/erts:
  hipe_bif0.c: Remove $Id$
  erts/preloaded: Add types and specs
  • Loading branch information
Erlang/OTP committed Feb 11, 2010
2 parents 2a96208 + 5cd9121 commit fbd9a5c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 75 deletions.
2 changes: 1 addition & 1 deletion erts/emulator/hipe/hipe_bif0.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* %CopyrightEnd%
*/
/* $Id$
/*
* hipe_bif0.c
*
* Compiler and linker support.
Expand Down
76 changes: 42 additions & 34 deletions erts/preloaded/src/erl_prim_loader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,25 @@
%% Used by escript and code
-export([set_primary_archive/3, release_archives/0]).

%% Internal function. Exported to avoid dialyzer warnings
-export([concat/1]).

-include_lib("kernel/include/file.hrl").

-type host() :: atom().

-record(prim_state, {debug :: boolean(),
cache,
primary_archive}).
-type prim_state() :: #prim_state{}.

-record(state,
{loader :: 'efile' | 'inet',
hosts = [] :: [host()], % hosts list (to boot from)
{loader :: 'efile' | 'inet',
hosts = [] :: [host()], % hosts list (to boot from)
id, % not used any more?
data, % data port etc
timeout, % idle timeout
n_timeouts, % Number of timeouts before archives are released
multi_get = false :: boolean(),
prim_state}). % state for efile code loader
data :: 'noport' | port(), % data port etc
timeout :: timeout(), % idle timeout
%% Number of timeouts before archives are released
n_timeouts :: non_neg_integer(),
multi_get = false :: boolean(),
prim_state :: prim_state()}). % state for efile code loader

-define(IDLE_TIMEOUT, 60000). %% tear inet connection after 1 minutes
-define(N_TIMEOUTS, 6). %% release efile archive after 6 minutes
Expand All @@ -89,8 +92,6 @@
end
end()).

-record(prim_state, {debug, cache, primary_archive}).

debug(#prim_state{debug = Deb}, Term) ->
case Deb of
false -> ok;
Expand Down Expand Up @@ -124,7 +125,7 @@ start(Id, Pgm0, Hosts) ->

start_it("ose_inet"=Cmd, Id, Pid, Hosts) ->
%% Setup reserved port for ose_inet driver (only OSE)
case catch erlang:open_port({spawn,Cmd},[binary]) of
case catch erlang:open_port({spawn,Cmd}, [binary]) of
{'EXIT',Why} ->
?dbg(ose_inet_port_open_fail, Why),
Why;
Expand Down Expand Up @@ -317,7 +318,7 @@ loop(State, Parent, Paths) ->
{Res,State1} = handle_get_cwd(State, Args),
{Res,State1,Paths};
{set_primary_archive,File,Bin,FileInfo} ->
{Res,State1} = handle_set_primary_archive(State, File, Bin,FileInfo),
{Res,State1} = handle_set_primary_archive(State, File, Bin, FileInfo),
{Res,State1,Paths};
release_archives ->
{Res,State1} = handle_release_archives(State),
Expand All @@ -326,7 +327,7 @@ loop(State, Parent, Paths) ->
{ignore,State,Paths}
end,
if Resp =:= ignore -> ok;
true -> Pid ! {self(),Resp}
true -> Pid ! {self(),Resp}, ok
end,
if
is_record(State2, state) ->
Expand All @@ -335,7 +336,7 @@ loop(State, Parent, Paths) ->
exit({bad_state, Req, State2})
end;
{'EXIT',Parent,W} ->
handle_stop(State),
_State1 = handle_stop(State),
exit(W);
{'EXIT',P,W} ->
State1 = handle_exit(State, P, W),
Expand Down Expand Up @@ -605,7 +606,6 @@ find_collect(U,Retry,AL,Delay,Acc) ->
_Garbage ->
?dbg(collect_garbage, _Garbage),
find_collect(U, Retry, AL, Delay, Acc)

after Delay ->
?dbg(collected, Acc),
case keymember(0, 1, Acc) of %% got high priority server?
Expand All @@ -619,7 +619,7 @@ sleep(Time) ->
receive after Time -> ok end.

inet_exit_port(State, Port, _Reason) when State#state.data =:= Port ->
State#state { data = noport, timeout = infinity };
State#state{data = noport, timeout = infinity};
inet_exit_port(State, _, _) ->
State.

Expand All @@ -629,7 +629,7 @@ inet_timeout_handler(State, _Parent) ->
if is_port(Tcp) -> ll_close(Tcp);
true -> ok
end,
State#state { timeout = infinity, data = noport }.
State#state{timeout = infinity, data = noport}.

%% -> {{ok,BinFile,Tag},State} | {{error,Reason},State}
inet_get_file_from_port(State, File, Paths) ->
Expand Down Expand Up @@ -659,9 +659,9 @@ inet_get_file_from_port1(_File, [], State) ->

inet_send_and_rcv(Msg, Tag, State) when State#state.data =:= noport ->
{ok,Tcp} = find_master(State#state.hosts), %% reconnect
inet_send_and_rcv(Msg, Tag, State#state { data = Tcp,
timeout = ?IDLE_TIMEOUT });
inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) ->
inet_send_and_rcv(Msg, Tag, State#state{data = Tcp,
timeout = ?IDLE_TIMEOUT});
inet_send_and_rcv(Msg, Tag, #state{data = Tcp, timeout = Timeout} = State) ->
prim_inet:send(Tcp, term_to_binary(Msg)),
receive
{tcp,Tcp,BinMsg} ->
Expand All @@ -679,13 +679,13 @@ inet_send_and_rcv(Msg, Tag, #state{data=Tcp,timeout=Timeout}=State) ->
end;
{tcp_closed,Tcp} ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, State#state { data = noport });
inet_send_and_rcv(Msg, Tag, State#state{data = noport});
{tcp_error,Tcp,_Reason} ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, inet_stop_port(State));
{'EXIT', Tcp, _} ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, State#state { data = noport })
inet_send_and_rcv(Msg, Tag, State#state{data = noport})
after Timeout ->
%% Ok we must reconnect
inet_send_and_rcv(Msg, Tag, inet_stop_port(State))
Expand Down Expand Up @@ -772,17 +772,18 @@ port_error(S, Error) ->

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec prim_init() -> prim_state().
prim_init() ->
Deb =
case init:get_argument(loader_debug) of
{ok, _} -> true;
error -> false
end,
cache_new(#prim_state{debug = Deb}).

prim_release_archives(PS) ->
debug(PS, release_archives),
{Res, PS2}= prim_do_release_archives(PS, get(), []),
{Res, PS2} = prim_do_release_archives(PS, get(), []),
debug(PS2, {return, Res}),
{Res, PS2}.

Expand Down Expand Up @@ -822,8 +823,8 @@ prim_set_primary_archive(PS, undefined, undefined, undefined) ->
debug(PS2, {return, Res}),
{Res, PS2}
end;
prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo)
when is_list(ArchiveFile), is_binary(ArchiveBin), is_record(FileInfo, file_info) ->
prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, #file_info{} = FileInfo)
when is_list(ArchiveFile), is_binary(ArchiveBin) ->
%% Try the archive file
debug(PS, {set_primary_archive, ArchiveFile, byte_size(ArchiveBin)}),
{Res3, PS3} =
Expand Down Expand Up @@ -861,6 +862,7 @@ prim_set_primary_archive(PS, ArchiveFile, ArchiveBin, FileInfo)
debug(PS3, {return, Res3}),
{Res3, PS3}.

-spec prim_get_file(prim_state(), file:filename()) -> {_, prim_state()}.
prim_get_file(PS, File) ->
debug(PS, {get_file, File}),
{Res2, PS2} =
Expand All @@ -885,7 +887,9 @@ prim_get_file(PS, File) ->
debug(PS, {return, Res2}),
{Res2, PS2}.

%% -> {{ok,List},State} | {{error,Reason},State}
-spec prim_list_dir(prim_state(), file:filename()) ->
{{'ok', [file:filename()]}, prim_state()}
| {{'error', term()}, prim_state()}.
prim_list_dir(PS, Dir) ->
debug(PS, {list_dir, Dir}),
{Res2, PS3} =
Expand Down Expand Up @@ -936,7 +940,9 @@ prim_list_dir(PS, Dir) ->
debug(PS, {return, Res2}),
{Res2, PS3}.

%% -> {{ok,Info},State} | {{error,Reason},State}
-spec prim_read_file_info(prim_state(), file:filename()) ->
{{'ok', #file_info{}}, prim_state()}
| {{'error', term()}, prim_state()}.
prim_read_file_info(PS, File) ->
debug(PS, {read_file_info, File}),
{Res2, PS2} =
Expand Down Expand Up @@ -976,6 +982,8 @@ prim_read_file_info(PS, File) ->
debug(PS2, {return, Res2}),
{Res2, PS2}.

-spec prim_get_cwd(prim_state(), [file:filename()]) ->
{{'error', term()} | {'ok', _}, prim_state()}.
prim_get_cwd(PS, []) ->
debug(PS, {get_cwd, []}),
Res = prim_file:get_cwd(),
Expand Down Expand Up @@ -1029,7 +1037,7 @@ apply_archive(PS, Fun, Acc, Archive) ->
{Acc2, PS};
Error ->
debug(PS, {cache, {clear, Error}}),
clear_cache(Archive, Cache),
ok = clear_cache(Archive, Cache),
debug(PS, {cache, Error}),
erase(Archive),
%% put(Archive, {Error, FI}),
Expand All @@ -1041,7 +1049,7 @@ apply_archive(PS, Fun, Acc, Archive) ->
end;
Error ->
debug(PS, {cache, {clear, Error}}),
clear_cache(Archive, Cache),
ok = clear_cache(Archive, Cache),
apply_archive(PS, Fun, Acc, Archive)
end
end.
Expand Down Expand Up @@ -1143,8 +1151,8 @@ send_all(U, [IP | AL], Cmd) ->
send_all(U, AL, Cmd);
send_all(_U, [], _) -> ok.

concat([A|T]) when is_atom(A) -> %Atom
atom_to_list(A) ++ concat(T);
%%concat([A|T]) when is_atom(A) -> %Atom
%% atom_to_list(A) ++ concat(T);
concat([C|T]) when C >= 0, C =< 255 ->
[C|concat(T)];
concat([S|T]) -> %String
Expand Down
Loading

0 comments on commit fbd9a5c

Please sign in to comment.