Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk-glue: Don't return from onCreate until LOOPER is created #131

Merged
merged 1 commit into from
Mar 20, 2021

Commits on Mar 20, 2021

  1. ndk-glue: Don't return from onCreate until LOOPER is created

    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 rust-mobile#116
    MarijnS95 committed Mar 20, 2021
    Configuration menu
    Copy the full SHA
    31cb4b7 View commit details
    Browse the repository at this point in the history