Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify event pipe before releasing NativeActivity resources
The design of ndk-glue seems to imply that the user of a `NativeActivity` resource, e.g. `NativeWindow` obtained from `ndk_glue::native_window()`, should hold a read lock on the resource as long as they are using it. Therefore, ndk-glue's `NativeActivity` callbacks related to resource release should: (1) notify the user of upcoming resource release (2) acquire a write lock on the handle, waiting for all read locks to be dropped, (3) drop the handle, (4) return from the callback. This allows the user to correctly release various objects derived from the resource (e.g. `EGLSurface` from `NativeWindow`) before it goes away. Currently, the order is 2-3-1-4, which can lead to a deadlock or a race condition, if the user drops the read lock at some earlier point while continuing to use objects derived from the resource. This commit fixes the order.
- Loading branch information