Fix race condition between ibus_bus_set_global_engine() and ibus_bus_get_global_engine().
authorYusuke Sato <yusukes@chromium.org>
Wed, 19 Jan 2011 01:55:16 +0000 (10:55 +0900)
committerYusuke Sato <yusukes@chromium.org>
Wed, 19 Jan 2011 01:55:16 +0000 (10:55 +0900)
commitb5382549a2f4009e0e4da20c7491ba28e7cca60f
tree29adf115303b0733d56ed53a9483a617e64db40c
parente194133baa0afc7fdb1befc18c2c1f516979a9be
Fix race condition between ibus_bus_set_global_engine() and ibus_bus_get_global_engine().

If focus moves between the two API calls, ibus_bus_get_global_engine() might return an unexpected engine name:

1. context A is focused, and the current global engine is "X".
2. ibus_bus_set_global_engine("Y") is called.
3. a user moves the focus from A to B. First, A's engine is set to NULL in bus_ibus_impl_set_focused_context(). Then, in the same function, B's engine is set to "X" (not "Y") since the _ibus_set_global_engine asynchronous call is not finished yet.
4. ibus_bus_set_global_engine("Y") async call successfully finishes. Context A's (not B's) engine is set to "Y", but context B, which has a focus, is not updated.
5. ibus_bus_get_global_engine() is called.

expected:
Y is returned.

actual:
X is returned. Since the context B has a focus, and B's engine is X.

BUG=http://crosbug.com/11031
TEST=see the bug

Review URL: http://codereview.appspot.com/4063041
bus/ibusimpl.c