Skip to content

Remove 'static mut' usage in features::os::kernel_version. #2029

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

Merged
merged 1 commit into from
May 20, 2023
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
15 changes: 8 additions & 7 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod os {
use crate::sys::utsname::uname;
use crate::Result;
use std::os::unix::ffi::OsStrExt;
use std::sync::atomic::{AtomicUsize, Ordering};

// Features:
// * atomic cloexec on socket: 2.6.27
Expand Down Expand Up @@ -72,15 +73,15 @@ mod os {
}

fn kernel_version() -> Result<usize> {
static mut KERNEL_VERS: usize = 0;
static KERNEL_VERS: AtomicUsize = AtomicUsize::new(0);
let mut kernel_vers = KERNEL_VERS.load(Ordering::Relaxed);

unsafe {
if KERNEL_VERS == 0 {
KERNEL_VERS = parse_kernel_version()?;
}

Ok(KERNEL_VERS)
if kernel_vers == 0 {
kernel_vers = parse_kernel_version()?;
KERNEL_VERS.store(kernel_vers, Ordering::Relaxed);
}

Ok(kernel_vers)
}

/// Check if the OS supports atomic close-on-exec for sockets
Expand Down