-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ndk-glue: Don't return from onCreate until LOOPER is created (#131)
Android only performs additional initialization like providing an input queue through `onInputQueueCreated` after the main initialization function (`ANativeActivity_onCreate`) returns. In some cases it is possible that the main thread spawned here hasn't attached a looper to its thread and assigned it to the accompanying `LOOPER` static variable yet, resulting in a `None` unwrap when Android provides us with an input queue. This race condition is simply solved by not returning from `fn init()` (`ANativeActivity_onCreate`) until the thread has finished its setup, through wrapping `LOOPER` in a `Mutex` and using a condition variable to signal when it is ready. This condition is intentionally not exposed to `on_input_queue_created` may we ever have a cleanup procedure that sets `LOOPER` back to `None`; any call to `onInputQueueCreated` in that state would be an error and should not block indefinitely. The `LOOPER` should simply be ready by the time `fn init()` returns. Fixes #116
- Loading branch information
Showing
2 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters