diff options
author | Dan Gudmundsson <[email protected]> | 2016-03-01 12:50:27 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2016-03-01 12:50:27 +0100 |
commit | 997168383605d68ad15f7af3d249ffc888c3e498 (patch) | |
tree | 5dc1ad74fe447fa8ea20eee1ba55073ee6e6077d /lib/wx/src | |
parent | 125016706cdfb30f6462076d5bf7c0144a3d2373 (diff) | |
download | otp-997168383605d68ad15f7af3d249ffc888c3e498.tar.gz otp-997168383605d68ad15f7af3d249ffc888c3e498.tar.bz2 otp-997168383605d68ad15f7af3d249ffc888c3e498.zip |
wx: Wait before throwing away early callbacks to wx_objects
If synced callbacks arrive early before the return value from
init had been synced to proc_lib. The callbacks where ignored.
Added a short timeout to avoid the scheduling raise but we don't want
block the wxe_server in case of deadlock in init, so sleep for a short
while and check again, and drop the callback when init takes to long.
Diffstat (limited to 'lib/wx/src')
-rw-r--r-- | lib/wx/src/wxe_server.erl | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/wx/src/wxe_server.erl b/lib/wx/src/wxe_server.erl index ae9440f890..693a008e3d 100644 --- a/lib/wx/src/wxe_server.erl +++ b/lib/wx/src/wxe_server.erl @@ -272,7 +272,7 @@ invoke_callback(Pid, Ev, Ref) -> wx:set_env(Env), wxe_util:cast(?WXE_CB_START, <<>>), try - case get_wx_object_state(Pid) of + case get_wx_object_state(Pid, 5) of ignore -> %% Ignore early events wxEvent:skip(Ref); @@ -307,16 +307,24 @@ invoke_callback_fun(Fun) -> wxe_util:cast(?WXE_CB_RETURN, Res). -get_wx_object_state(Pid) -> +get_wx_object_state(Pid, N) when N > 0 -> case process_info(Pid, dictionary) of {dictionary, Dict} -> case lists:keysearch('_wx_object_',1,Dict) of - {value, {'_wx_object_', {_Mod, '_wx_init_'}}} -> ignore; - {value, {'_wx_object_', Value}} -> Value; - _ -> ignore + {value, {'_wx_object_', {_Mod, '_wx_init_'}}} -> + timer:sleep(50), + get_wx_object_state(Pid, N-1); + {value, {'_wx_object_', Value}} -> + Value; + _ -> + ignore end; - _ -> ignore - end. + _ -> + ignore + end; +get_wx_object_state(_, _) -> + ignore. + attach_fun(Fun, S = #state{cb=CB,cb_cnt=Next}) -> case gb_trees:lookup(Fun,CB) of |