浏览代码

代码优化

master
jjmj 5 年前
父节点
当前提交
7b45e05f39
共有 1 个文件被更改,包括 30 次插入14 次删除
  1. +30
    -14
      src/gen_ipc.erl

+ 30
- 14
src/gen_ipc.erl 查看文件

@ -152,8 +152,10 @@
-type eventCallbackResult() :: -type eventCallbackResult() ::
{'reply', Reply :: term(), NewState :: term()} | % 用作gen_server模式时快速响应进入消息接收 {'reply', Reply :: term(), NewState :: term()} | % 用作gen_server模式时快速响应进入消息接收
{'sreply', Reply :: term(), NextStatus :: term(), NewState :: term()} | % 用作gen_ipc模式便捷式返回reply 而不用把reply放在actions列表中
{'noreply', NewState :: term()} | % 用作gen_server模式时快速响应进入消息接收 {'noreply', NewState :: term()} | % 用作gen_server模式时快速响应进入消息接收
{'reply', Reply :: term(), NewState :: term(), Options :: hibernate | {doAfter, Args}} | % 用作gen_server模式时快速响应进入消息接收 {'reply', Reply :: term(), NewState :: term(), Options :: hibernate | {doAfter, Args}} | % 用作gen_server模式时快速响应进入消息接收
{'sreply', Reply :: term(), NextStatus :: term(), NewState :: term(), Actions :: [eventAction(), ...]} | % 用作gen_ipc模式便捷式返回reply 而不用把reply放在actions列表中
{'noreply', NewState :: term(), Options :: hibernate | {doAfter, Args}} | % 用作gen_server模式时快速响应进入循环 {'noreply', NewState :: term(), Options :: hibernate | {doAfter, Args}} | % 用作gen_server模式时快速响应进入循环
{'nextStatus', NextStatus :: term(), NewState :: term()} | % {next_status,NextStatus,NewData,[]} {'nextStatus', NextStatus :: term(), NewState :: term()} | % {next_status,NextStatus,NewData,[]}
{'nextStatus', NextStatus :: term(), NewState :: term(), Actions :: [eventAction(), ...]} | % Status transition, maybe to the same status {'nextStatus', NextStatus :: term(), NewState :: term(), Actions :: [eventAction(), ...]} | % Status transition, maybe to the same status
@ -720,12 +722,16 @@ cast({via, RegMod, Name}, Msg) ->
_:_ -> ok _:_ -> ok
end; end;
cast({Name, Node} = Dest, Msg) when is_atom(Name), is_atom(Node) -> cast({Name, Node} = Dest, Msg) when is_atom(Name), is_atom(Node) ->
try erlang:send(Dest, {'$gen_cast', Msg})
try
erlang:send(Dest, {'$gen_cast', Msg}),
ok
catch catch
error:_ -> ok error:_ -> ok
end; end;
cast(Dest, Msg) -> cast(Dest, Msg) ->
try erlang:send(Dest, {'$gen_cast', Msg})
try
erlang:send(Dest, {'$gen_cast', Msg}),
ok
catch catch
error:_ -> ok error:_ -> ok
end. end.
@ -738,7 +744,9 @@ abcast(Nodes, Name, Msg) when is_list(Nodes), is_atom(Name) ->
doAbcast(Nodes, Name, Msg). doAbcast(Nodes, Name, Msg).
doAbcast([Node | Nodes], Name, Msg) when is_atom(Node) -> doAbcast([Node | Nodes], Name, Msg) when is_atom(Node) ->
try erlang:send({Name, Node}, {'$gen_cast', Msg})
try
erlang:send({Name, Node}, {'$gen_cast', Msg}),
ok
catch catch
error:_ -> ok error:_ -> ok
end, end,
@ -1381,17 +1389,17 @@ handleEnterCallbackRet(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEv
dealEnterCallbackRet(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false); dealEnterCallbackRet(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false);
{keepStatus, NewState, Actions} -> {keepStatus, NewState, Actions} ->
parseEnterActionsList(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false, Actions); parseEnterActionsList(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false, Actions);
keepStatusData ->
keepStatusState ->
dealEnterCallbackRet(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false); dealEnterCallbackRet(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false);
{keepStatusData, Actions} ->
{keepStatusState, Actions} ->
parseEnterActionsList(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false, Actions); parseEnterActionsList(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, false, Actions);
{repeatStatus, NewState} -> {repeatStatus, NewState} ->
dealEnterCallbackRet(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true); dealEnterCallbackRet(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true);
{repeatStatus, NewState, Actions} -> {repeatStatus, NewState, Actions} ->
parseEnterActionsList(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true, Actions); parseEnterActionsList(CycleData, PrevStatus, NewState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true, Actions);
repeatStatusData ->
repeatStatusState ->
dealEnterCallbackRet(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true); dealEnterCallbackRet(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true);
{repeatStatusData, Actions} ->
{repeatStatusState, Actions} ->
parseEnterActionsList(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true, Actions); parseEnterActionsList(CycleData, PrevStatus, CurState, CurStatus, Debug, LeftEvents, Timeouts, NextEvents, IsPostpone, IsHibernate, DoAfter, true, Actions);
stop -> stop ->
terminate(exit, normal, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents); terminate(exit, normal, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents);
@ -1428,17 +1436,17 @@ handleEventCallbackRet(CycleData, CurStatus, CurState, Debug, LeftEvents, Result
dealEventCallbackRet(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, false); dealEventCallbackRet(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, false);
{keepStatus, NewState, Actions} -> {keepStatus, NewState, Actions} ->
parseEventActionsList(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, false, Actions, CallbackForm); parseEventActionsList(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, false, Actions, CallbackForm);
keepStatusData ->
keepStatusState ->
dealEventCallbackRet(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, false); dealEventCallbackRet(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, false);
{keepStatusData, Actions} ->
{keepStatusState, Actions} ->
parseEventActionsList(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, false, Actions, CallbackForm); parseEventActionsList(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, false, Actions, CallbackForm);
{repeatStatus, NewState} -> {repeatStatus, NewState} ->
dealEventCallbackRet(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, true); dealEventCallbackRet(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, true);
{repeatStatus, NewState, Actions} -> {repeatStatus, NewState, Actions} ->
parseEventActionsList(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, true, Actions, CallbackForm); parseEventActionsList(CycleData, CurStatus, NewState, CurStatus, Debug, LeftEvents, true, Actions, CallbackForm);
repeatStatusData ->
repeatStatusState ->
dealEventCallbackRet(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, true); dealEventCallbackRet(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, true);
{repeatStatusData, Actions} ->
{repeatStatusState, Actions} ->
parseEventActionsList(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, true, Actions, CallbackForm); parseEventActionsList(CycleData, CurStatus, CurState, CurStatus, Debug, LeftEvents, true, Actions, CallbackForm);
stop -> stop ->
terminate(exit, normal, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents); terminate(exit, normal, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents);
@ -1450,11 +1458,11 @@ handleEventCallbackRet(CycleData, CurStatus, CurState, Debug, LeftEvents, Result
replyThenTerminate(exit, Reason, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents, Replies); replyThenTerminate(exit, Reason, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents, Replies);
{stopReply, Reason, Replies, NewState} -> {stopReply, Reason, Replies, NewState} ->
replyThenTerminate(exit, Reason, ?STACKTRACE(), CycleData, CurStatus, NewState, Debug, LeftEvents, Replies); replyThenTerminate(exit, Reason, ?STACKTRACE(), CycleData, CurStatus, NewState, Debug, LeftEvents, Replies);
{reply, Reply, NewState} when CallbackForm == ?CB_FORM_EVENT ->
{reply, Reply, NewState} ->
reply(From, Reply), reply(From, Reply),
NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}), NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}),
receiveMsgWait(CycleData, CurStatus, NewState, NewDebug, false); receiveMsgWait(CycleData, CurStatus, NewState, NewDebug, false);
{reply, Reply, NewState, Option} when CallbackForm == ?CB_FORM_EVENT ->
{reply, Reply, NewState, Option} ->
reply(From, Reply), reply(From, Reply),
NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}), NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}),
case Option of case Option of
@ -1465,6 +1473,14 @@ handleEventCallbackRet(CycleData, CurStatus, CurState, Debug, LeftEvents, Result
_Ret -> _Ret ->
terminate(error, {bad_reply_option, _Ret}, ?STACKTRACE(), CycleData, CurStatus, NewState, Debug, []) terminate(error, {bad_reply_option, _Ret}, ?STACKTRACE(), CycleData, CurStatus, NewState, Debug, [])
end; end;
{sreply, Reply, NewStatus, NewState} ->
reply(From, Reply),
NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}),
dealEventCallbackRet(CycleData, CurStatus, NewState, NewStatus, NewDebug, LeftEvents, NewStatus =/= CurStatus);
{sreply, Reply, NewStatus, NewState, Actions} ->
reply(From, Reply),
NewDebug = ?SYS_DEBUG(Debug, {out, Reply, From}),
parseEventActionsList(CycleData, CurStatus, NewState, NewStatus, NewDebug, LeftEvents, NewStatus =/= CurStatus, Actions, CallbackForm);
_ -> _ ->
terminate(error, {bad_return_from_status_function, Result}, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents) terminate(error, {bad_return_from_status_function, Result}, ?STACKTRACE(), CycleData, CurStatus, CurState, Debug, LeftEvents)
end. end.
@ -2091,7 +2107,7 @@ print_event(Dev, SystemEvent, Name) ->
{out, Reply, {To, _Tag}} -> {out, Reply, {To, _Tag}} ->
io:format(Dev, "*DBG* ~tp send ~tp to ~tw~n", [Name, Reply, To]); io:format(Dev, "*DBG* ~tp send ~tp to ~tw~n", [Name, Reply, To]);
{out, Replies} -> {out, Replies} ->
io:format(Dev, "*DBG* ~tp send ~tp to list ~tw~n", [Name, Replies]);
io:format(Dev, "*DBG* ~tp sendto list ~tw~n", [Name, Replies]);
{enter, Status} -> {enter, Status} ->
io:format(Dev, "*DBG* ~tp enter in status ~tp~n", [Name, Status]); io:format(Dev, "*DBG* ~tp enter in status ~tp~n", [Name, Status]);
{start_timer, Action, Status} -> {start_timer, Action, Status} ->

正在加载...
取消
保存