fixed race condition

when using g.waiting as a test for spurious wakupe
as well as whether the ui thread is waiting, the
on_input callback might think the ui thread was
waiting when it hasnt even woke up from the last
condition signal.