diff options
author | Dan Gudmundsson <[email protected]> | 2015-12-01 16:43:08 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2015-12-01 16:43:08 +0100 |
commit | f0ab82279fa6fc7c91d9b3c193d1890b7c83e39b (patch) | |
tree | 3976393a55398e7ba60e853529c3e8c8b24fa765 | |
parent | 617387025b698c7c7b1d102e35234b2c65dda335 (diff) | |
download | otp-f0ab82279fa6fc7c91d9b3c193d1890b7c83e39b.tar.gz otp-f0ab82279fa6fc7c91d9b3c193d1890b7c83e39b.tar.bz2 otp-f0ab82279fa6fc7c91d9b3c193d1890b7c83e39b.zip |
wx: Remove call to disconnect_impl from server
The server might wait for the result of a call to disconnect_impl
which can now be delayed, that might cause a callback to never be
invoked and thus hang the driver thread.
To avoid that dispatch the disconnect_impl call from user process
instead of server.
-rw-r--r-- | lib/wx/src/wxe_server.erl | 21 | ||||
-rw-r--r-- | lib/wx/src/wxe_util.erl | 17 |
2 files changed, 17 insertions, 21 deletions
diff --git a/lib/wx/src/wxe_server.erl b/lib/wx/src/wxe_server.erl index cc253b1143..ae9440f890 100644 --- a/lib/wx/src/wxe_server.erl +++ b/lib/wx/src/wxe_server.erl @@ -352,25 +352,8 @@ handle_disconnect(Object, Evh = #evh{cb=Fun}, From, State0 = #state{users=Users0, cb=Callbacks}) -> #user{events=Evs0} = gb_trees:get(From, Users0), FunId = gb_trees:lookup(Fun, Callbacks), - case find_handler(Evs0, Object, Evh#evh{cb=FunId}) of - [] -> - {reply, false, State0}; - Handlers -> - case disconnect(Object,Handlers) of - #evh{} -> {reply, true, State0}; - Result -> {reply, Result, State0} - end - end. - -disconnect(Object,[Ev|Evs]) -> - try wxEvtHandler:disconnect_impl(Object,Ev) of - true -> Ev; - false -> disconnect(Object, Evs); - Error -> Error - catch _:_ -> - false - end; -disconnect(_, []) -> false. + Handlers = find_handler(Evs0, Object, Evh#evh{cb=FunId}), + {reply, {try_in_order, Handlers}, State0}. find_handler([{Object,Evh}|Evs], Object, Match) -> case match_handler(Match, Evh) of diff --git a/lib/wx/src/wxe_util.erl b/lib/wx/src/wxe_util.erl index 1983e6783a..398ceddd4f 100644 --- a/lib/wx/src/wxe_util.erl +++ b/lib/wx/src/wxe_util.erl @@ -127,8 +127,21 @@ connect_cb(Object,EvData0 = #evh{cb=Callback}) -> disconnect_cb(Object,EvData) -> Server = (wx:get_env())#wx_env.sv, - gen_server:call(Server, {disconnect_cb,Object,EvData}, infinity). - + {try_in_order, Handlers} = + gen_server:call(Server, {disconnect_cb,Object,EvData}, infinity), + disconnect(Object, Handlers). + +disconnect(Object,[Ev|Evs]) -> + try wxEvtHandler:disconnect_impl(Object,Ev) of + true -> true; + false -> disconnect(Object, Evs); + Error -> Error + catch _:_ -> + false + end; +disconnect(_, []) -> false. + + debug_cast(1, Op, _Args, _Port) -> check_previous(), case ets:lookup(wx_debug_info,Op) of |