diff options
author | Siri Hansen <[email protected]> | 2014-03-25 09:46:49 +0100 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2014-03-25 09:47:19 +0100 |
commit | aa2dfd7c30d3ca3318498bcbf4155dad175b6d7e (patch) | |
tree | 3b7d38226fe79cc2b19162313e0eac8a44b697f0 /lib/stdlib/src/gen_event.erl | |
parent | 1eee4ded1b435d3728fc75ad384626c80025bb3b (diff) | |
parent | cbcac6f0d55907dda2e0c385eba44eac2e7923d2 (diff) | |
download | otp-aa2dfd7c30d3ca3318498bcbf4155dad175b6d7e.tar.gz otp-aa2dfd7c30d3ca3318498bcbf4155dad175b6d7e.tar.bz2 otp-aa2dfd7c30d3ca3318498bcbf4155dad175b6d7e.zip |
Merge branch 'vinoski/sys-get-rep-state2'
* vinoski/sys-get-rep-state2:
remove tuple funs from special process documentation
fix sys:get_state/1,2 and sys:replace_state/2,3 when sys suspended
OTP-11817
Diffstat (limited to 'lib/stdlib/src/gen_event.erl')
-rw-r--r-- | lib/stdlib/src/gen_event.erl | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/lib/stdlib/src/gen_event.erl b/lib/stdlib/src/gen_event.erl index 7629e88fbf..d39dd89d3a 100644 --- a/lib/stdlib/src/gen_event.erl +++ b/lib/stdlib/src/gen_event.erl @@ -40,6 +40,8 @@ system_continue/3, system_terminate/4, system_code_change/4, + system_get_state/1, + system_replace_state/2, format_status/2]). -export_type([handler/0, handler_args/0, add_handler_ret/0, @@ -229,24 +231,6 @@ wake_hib(Parent, ServerName, MSL, Debug) -> fetch_msg(Parent, ServerName, MSL, Debug, Hib) -> receive - {system, From, get_state} -> - States = [{Mod,Id,State} || #handler{module=Mod, id=Id, state=State} <- MSL], - sys:handle_system_msg(get_state, From, Parent, ?MODULE, Debug, - {States, [ServerName, MSL, Hib]}, Hib); - {system, From, {replace_state, StateFun}} -> - {NMSL, NStates} = - lists:unzip([begin - Cur = {Mod,Id,State}, - try - NState = {Mod,Id,NS} = StateFun(Cur), - {HS#handler{state=NS}, NState} - catch - _:_ -> - {HS, Cur} - end - end || #handler{module=Mod, id=Id, state=State}=HS <- MSL]), - sys:handle_system_msg(replace_state, From, Parent, ?MODULE, Debug, - {NStates, [ServerName, NMSL, Hib]}, Hib); {system, From, Req} -> sys:handle_system_msg(Req, From, Parent, ?MODULE, Debug, [ServerName, MSL, Hib],Hib); @@ -383,6 +367,23 @@ system_code_change([ServerName, MSL, Hib], Module, OldVsn, Extra) -> MSL), {ok, [ServerName, MSL1, Hib]}. +system_get_state([_ServerName, MSL, _Hib]) -> + {ok, [{Mod,Id,State} || #handler{module=Mod, id=Id, state=State} <- MSL]}. + +system_replace_state(StateFun, [ServerName, MSL, Hib]) -> + {NMSL, NStates} = + lists:unzip([begin + Cur = {Mod,Id,State}, + try + NState = {Mod,Id,NS} = StateFun(Cur), + {HS#handler{state=NS}, NState} + catch + _:_ -> + {HS, Cur} + end + end || #handler{module=Mod, id=Id, state=State}=HS <- MSL]), + {ok, NStates, [ServerName, NMSL, Hib]}. + %%----------------------------------------------------------------- %% Format debug messages. Print them as the call-back module sees %% them, not as the real erlang messages. Use trace for that. |