diff options
author | Siri Hansen <[email protected]> | 2014-06-27 15:54:18 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2014-10-08 09:33:57 +0200 |
commit | a7289521bcb7494f33e86360b096844c5b6bc68d (patch) | |
tree | a0b3e10f1174b534f4f3c426284d2a35c9ab6171 | |
parent | c1acfc6283d3146d6f10dfd8c4b96a330f7da19f (diff) | |
download | otp-a7289521bcb7494f33e86360b096844c5b6bc68d.tar.gz otp-a7289521bcb7494f33e86360b096844c5b6bc68d.tar.bz2 otp-a7289521bcb7494f33e86360b096844c5b6bc68d.zip |
Rebase supervisor
Remove duplicated code related to checking of supervisor flags.
-rw-r--r-- | lib/stdlib/src/supervisor.erl | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl index ede2742875..08d4767e46 100644 --- a/lib/stdlib/src/supervisor.erl +++ b/lib/stdlib/src/supervisor.erl @@ -610,13 +610,11 @@ terminate(_Reason, State) -> code_change(_, State, _) -> case (State#state.module):init(State#state.args) of {ok, {SupFlags, StartSpec}} -> - case catch check_flags(SupFlags) of - ok -> - {Strategy, MaxIntensity, Period} = SupFlags, - update_childspec(State#state{strategy = Strategy, - intensity = MaxIntensity, - period = Period}, - StartSpec); + case set_flags(SupFlags, State) of + {ok, State1} -> + update_childspec(State1, StartSpec); + {invalid_type, SupFlags} -> + {error, {bad_flags, SupFlags}}; % backwards compatibility Error -> {error, Error} end; @@ -626,14 +624,6 @@ code_change(_, State, _) -> Error end. -check_flags({Strategy, MaxIntensity, Period}) -> - validStrategy(Strategy), - validIntensity(MaxIntensity), - validPeriod(Period), - ok; -check_flags(What) -> - {bad_flags, What}. - update_childspec(State, StartSpec) when ?is_simple(State) -> case check_startspec(StartSpec) of {ok, [Child]} -> @@ -1188,25 +1178,27 @@ remove_child(Child, State) -> %% Returns: {ok, state()} | Error %%----------------------------------------------------------------- init_state(SupName, Type, Mod, Args) -> - case catch init_state1(SupName, Type, Mod, Args) of - {ok, State} -> - {ok, State}; - Error -> - Error + set_flags(Type, #state{name = supname(SupName,Mod), + module = Mod, + args = Args}). + +set_flags(Flags, State) -> + try check_flags(Flags) of + {ok, {Strategy, MaxIntensity, Period}} -> + {ok, State#state{strategy = Strategy, + intensity = MaxIntensity, + period = Period}} + catch + Thrown -> Thrown end. -init_state1(SupName, {Strategy, MaxIntensity, Period}, Mod, Args) -> +check_flags({Strategy, MaxIntensity, Period} = Flags) -> validStrategy(Strategy), validIntensity(MaxIntensity), validPeriod(Period), - {ok, #state{name = supname(SupName,Mod), - strategy = Strategy, - intensity = MaxIntensity, - period = Period, - module = Mod, - args = Args}}; -init_state1(_SupName, Type, _, _) -> - {invalid_type, Type}. + {ok, Flags} ; +check_flags(What) -> + throw({invalid_type, What}). validStrategy(simple_one_for_one) -> true; validStrategy(one_for_one) -> true; |