android_activity/
waker.rs1use std::ptr::NonNull;
2
3#[cfg(doc)]
4use crate::AndroidApp;
5
6pub struct AndroidAppWaker {
8 looper: NonNull<ndk_sys::ALooper>,
9}
10
11impl Clone for AndroidAppWaker {
12 fn clone(&self) -> Self {
13 unsafe { ndk_sys::ALooper_acquire(self.looper.as_ptr()) }
14 Self {
15 looper: self.looper,
16 }
17 }
18}
19
20impl Drop for AndroidAppWaker {
21 fn drop(&mut self) {
22 unsafe { ndk_sys::ALooper_release(self.looper.as_ptr()) }
23 }
24}
25
26unsafe impl Send for AndroidAppWaker {}
27unsafe impl Sync for AndroidAppWaker {}
28
29impl AndroidAppWaker {
30 pub(crate) unsafe fn new(looper: *mut ndk_sys::ALooper) -> Self {
36 assert!(!looper.is_null(), "looper pointer must not be null");
37 unsafe {
38 ndk_sys::ALooper_acquire(looper);
40 AndroidAppWaker {
41 looper: NonNull::new_unchecked(looper),
42 }
43 }
44 }
45
46 pub fn wake(&self) {
53 unsafe {
54 ndk_sys::ALooper_wake(self.looper.as_ptr());
55 }
56 }
57}