mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Clean up fd_monitor getter
No need for UnsafeCell
This commit is contained in:
parent
fb700ca50d
commit
617b61cd3a
1 changed files with 6 additions and 11 deletions
17
src/io.rs
17
src/io.rs
|
@ -20,9 +20,10 @@ use errno::Errno;
|
|||
use libc::{EAGAIN, EINTR, ENOENT, ENOTDIR, EPIPE, EWOULDBLOCK, STDOUT_FILENO};
|
||||
use nix::fcntl::OFlag;
|
||||
use nix::sys::stat::Mode;
|
||||
use once_cell::sync::Lazy;
|
||||
#[cfg(not(target_has_atomic = "64"))]
|
||||
use portable_atomic::AtomicU64;
|
||||
use std::cell::{RefCell, UnsafeCell};
|
||||
use std::cell::RefCell;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::fd::{AsRawFd, IntoRawFd, OwnedFd, RawFd};
|
||||
|
@ -1033,14 +1034,8 @@ const NOCLOB_ERROR: &wstr = L!("The file '%ls' already exists");
|
|||
const OPEN_MASK: Mode = Mode::from_bits_truncate(0o666);
|
||||
|
||||
/// Provide the fd monitor used for background fillthread operations.
|
||||
fn fd_monitor() -> &'static mut FdMonitor {
|
||||
// Deliberately leaked to avoid shutdown dtors.
|
||||
static mut FDM: *const UnsafeCell<FdMonitor> = std::ptr::null();
|
||||
unsafe {
|
||||
if FDM.is_null() {
|
||||
FDM = Box::into_raw(Box::new(UnsafeCell::new(FdMonitor::new())))
|
||||
}
|
||||
}
|
||||
let ptr: *mut FdMonitor = unsafe { (*FDM).get() };
|
||||
unsafe { &mut *ptr }
|
||||
static FD_MONITOR: Lazy<FdMonitor> = Lazy::new(FdMonitor::new);
|
||||
|
||||
pub fn fd_monitor() -> &'static FdMonitor {
|
||||
&FD_MONITOR
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue