diff options
author | Dan Gudmundsson <[email protected]> | 2015-07-07 10:38:38 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2015-07-07 10:38:38 +0200 |
commit | fcbc24440945a13b379b2b6135599c982bf8bdf0 (patch) | |
tree | 5c04db3494dfe5c196ab291da7bb2dcddadcf101 /lib/wx/src/wxe_server.erl | |
parent | 70cb9432dc03ac9435b2c8c5fe2e8fd0608015dc (diff) | |
download | otp-fcbc24440945a13b379b2b6135599c982bf8bdf0.tar.gz otp-fcbc24440945a13b379b2b6135599c982bf8bdf0.tar.bz2 otp-fcbc24440945a13b379b2b6135599c982bf8bdf0.zip |
wx: Add event callback fastpath
Avoids spawn but can deadlock
Diffstat (limited to 'lib/wx/src/wxe_server.erl')
-rw-r--r-- | lib/wx/src/wxe_server.erl | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/wx/src/wxe_server.erl b/lib/wx/src/wxe_server.erl index 6679fcfbe1..cc253b1143 100644 --- a/lib/wx/src/wxe_server.erl +++ b/lib/wx/src/wxe_server.erl @@ -240,6 +240,8 @@ handle_connect(Object, EvData=#evh{handler=Handler}, invoke_cb({{Ev=#wx{}, Ref=#wx_ref{}}, FunId,_}, _S) -> %% Event callbacks case get(FunId) of + {{nospawn, Fun}, _} when is_function(Fun) -> + invoke_callback_fun(fun() -> Fun(Ev, Ref), <<>> end); {Fun,_} when is_function(Fun) -> invoke_callback(fun() -> Fun(Ev, Ref), <<>> end); {Pid,_} when is_pid(Pid) -> %% wx_object sync event @@ -258,21 +260,10 @@ invoke_cb({FunId, Args, _}, _S) when is_list(Args), is_integer(FunId) -> invoke_callback(Fun) -> Env = get(?WXE_IDENTIFIER), - CB = fun() -> - wx:set_env(Env), - wxe_util:cast(?WXE_CB_START, <<>>), - Res = try - Return = Fun(), - true = is_binary(Return), - Return - catch _:Reason -> - ?log("Callback fun crashed with {'EXIT, ~p, ~p}~n", - [Reason, erlang:get_stacktrace()]), - <<>> - end, - wxe_util:cast(?WXE_CB_RETURN, Res) - end, - spawn(CB), + spawn(fun() -> + wx:set_env(Env), + invoke_callback_fun(Fun) + end), ok. invoke_callback(Pid, Ev, Ref) -> @@ -302,6 +293,20 @@ invoke_callback(Pid, Ev, Ref) -> spawn(CB), ok. +invoke_callback_fun(Fun) -> + wxe_util:cast(?WXE_CB_START, <<>>), + Res = try + Return = Fun(), + true = is_binary(Return), + Return + catch _:Reason -> + ?log("Callback fun crashed with {'EXIT, ~p, ~p}~n", + [Reason, erlang:get_stacktrace()]), + <<>> + end, + wxe_util:cast(?WXE_CB_RETURN, Res). + + get_wx_object_state(Pid) -> case process_info(Pid, dictionary) of {dictionary, Dict} -> |