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: Replace ancient lazy_static crate with once_cell #285

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ndk-glue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ndk = { path = "../ndk", version = "0.6.0" }
ndk-context = { path = "../ndk-context", version = "0.1.1" }
ndk-macro = { path = "../ndk-macro", version = "0.3.0" }
ndk-sys = { path = "../ndk-sys", version = "0.3.0" }
lazy_static = "1.4.0"
once_cell = "1"
libc = "0.2.84"
log = "0.4.14"
android_logger = { version = "0.10.1", optional = true }
Expand Down
24 changes: 10 additions & 14 deletions ndk-glue/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use lazy_static::lazy_static;
use log::Level;
use ndk::input_queue::InputQueue;
use ndk::looper::{FdEvent, ForeignLooper, ThreadLooper};
use ndk::native_activity::NativeActivity;
use ndk::native_window::NativeWindow;
use ndk_sys::{AInputQueue, ANativeActivity, ANativeWindow, ARect};
use once_cell::sync::Lazy;
use std::ffi::{CStr, CString};
use std::fs::File;
use std::io::{BufRead, BufReader};
Expand Down Expand Up @@ -46,12 +46,10 @@ pub fn android_log(level: Level, tag: &CStr, msg: &CStr) {
}
}

lazy_static! {
static ref NATIVE_WINDOW: RwLock<Option<NativeWindow>> = Default::default();
static ref INPUT_QUEUE: RwLock<Option<InputQueue>> = Default::default();
static ref CONTENT_RECT: RwLock<Rect> = Default::default();
static ref LOOPER: Mutex<Option<ForeignLooper>> = Default::default();
}
static NATIVE_WINDOW: Lazy<RwLock<Option<NativeWindow>>> = Lazy::new(Default::default);
static INPUT_QUEUE: Lazy<RwLock<Option<InputQueue>>> = Lazy::new(Default::default);
static CONTENT_RECT: Lazy<RwLock<Rect>> = Lazy::new(Default::default);
static LOOPER: Lazy<Mutex<Option<ForeignLooper>>> = Lazy::new(Default::default);

static mut NATIVE_ACTIVITY: Option<NativeActivity> = None;

Expand All @@ -72,13 +70,11 @@ pub fn content_rect() -> Rect {
CONTENT_RECT.read().unwrap().clone()
}

lazy_static! {
static ref PIPE: [RawFd; 2] = {
let mut pipe: [RawFd; 2] = Default::default();
unsafe { libc::pipe(pipe.as_mut_ptr()) };
pipe
};
}
static PIPE: Lazy<[RawFd; 2]> = Lazy::new(|| {
let mut pipe: [RawFd; 2] = Default::default();
unsafe { libc::pipe(pipe.as_mut_ptr()) };
pipe
});

pub fn poll_events() -> Option<Event> {
unsafe {
Expand Down