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

Replaces static mutable references in entry #4418

Merged
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
40 changes: 20 additions & 20 deletions entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use {
cmp,
ffi::OsStr,
iter::repeat_with,
sync::{Arc, Mutex, Once},
sync::{Arc, Mutex, Once, OnceLock},
thread::{self, JoinHandle},
time::Instant,
},
Expand All @@ -41,7 +41,7 @@ use {
pub type EntrySender = Sender<Vec<Entry>>;
pub type EntryReceiver = Receiver<Vec<Entry>>;

static mut API: Option<Container<Api>> = None;
static API: OnceLock<Container<Api>> = OnceLock::new();

pub fn init_poh() {
init(OsStr::new("libpoh-simd.so"));
Expand All @@ -51,23 +51,23 @@ fn init(name: &OsStr) {
static INIT_HOOK: Once = Once::new();

info!("Loading {:?}", name);
unsafe {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

INIT_HOOK.call_once(|| {
let path;
let lib_name = if let Some(perf_libs_path) = solana_perf::perf_libs::locate_perf_libs()
{
solana_perf::perf_libs::append_to_ld_library_path(
perf_libs_path.to_str().unwrap_or("").to_string(),
);
path = perf_libs_path.join(name);
path.as_os_str()
} else {
name
};
INIT_HOOK.call_once(|| {
let path;
let lib_name = if let Some(perf_libs_path) = solana_perf::perf_libs::locate_perf_libs() {
solana_perf::perf_libs::append_to_ld_library_path(
perf_libs_path.to_str().unwrap_or("").to_string(),
);
path = perf_libs_path.join(name);
path.as_os_str()
} else {
name
};

API = Container::load(lib_name).ok();
})
}
match unsafe { Container::load(lib_name) } {
Ok(api) => _ = API.set(api),
Err(err) => error!("Unable to load {lib_name:?}: {err}"),
}
bw-solana marked this conversation as resolved.
Show resolved Hide resolved
})
}

pub fn api() -> Option<&'static Container<Api<'static>>> {
Expand All @@ -77,10 +77,10 @@ pub fn api() -> Option<&'static Container<Api<'static>>> {
if std::env::var("TEST_PERF_LIBS").is_ok() {
init_poh()
}
})
});
}

unsafe { API.as_ref() }
API.get()
}

#[derive(SymBorApi)]
Expand Down
Loading