Fix visibility levels

This commit is contained in:
Ruihan Li
2024-10-24 23:50:56 +08:00
committed by Tate, Hongliang Tian
parent 83b6c03bd8
commit 781ee0fa71
2 changed files with 35 additions and 38 deletions

View File

@ -19,10 +19,10 @@ use crate::{
/// An epoll entry that is contained in an epoll file. /// An epoll entry that is contained in an epoll file.
/// ///
/// Each epoll entry can be added, modified, or deleted by the `EpollCtl` command. /// Each epoll entry can be added, modified, or deleted by the `EpollCtl` command.
pub struct EpollEntry { pub(super) struct EpollEntry {
// The file descriptor and the file // The file descriptor and the file.
key: EpollEntryKey, key: EpollEntryKey,
// The event masks and flags // The event masks and flags.
inner: Mutex<EpollEntryInner>, inner: Mutex<EpollEntryInner>,
// The observer that receives events. // The observer that receives events.
// //
@ -32,7 +32,7 @@ pub struct EpollEntry {
} }
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct EpollEntryKey { pub(super) struct EpollEntryKey {
fd: FileDesc, fd: FileDesc,
file: KeyableWeak<dyn FileLike>, file: KeyableWeak<dyn FileLike>,
} }
@ -63,7 +63,7 @@ struct EpollEntryInner {
impl EpollEntry { impl EpollEntry {
/// Creates a new epoll entry associated with the given epoll file. /// Creates a new epoll entry associated with the given epoll file.
pub fn new( pub(super) fn new(
fd: FileDesc, fd: FileDesc,
file: KeyableWeak<dyn FileLike>, file: KeyableWeak<dyn FileLike>,
ready_set: Arc<ReadySet>, ready_set: Arc<ReadySet>,
@ -88,11 +88,11 @@ impl EpollEntry {
}) })
} }
/// Get the file associated with this epoll entry. /// Gets the file associated with this epoll entry.
/// ///
/// Since an epoll entry only holds a weak reference to the file, /// Since an epoll entry only holds a weak reference to the file,
/// it is possible (albeit unlikely) that the file has been dropped. /// it is possible (albeit unlikely) that the file has been dropped.
pub fn file(&self) -> Option<Arc<dyn FileLike>> { fn file(&self) -> Option<Arc<dyn FileLike>> {
self.key.file.upgrade().map(KeyableArc::into) self.key.file.upgrade().map(KeyableArc::into)
} }
@ -101,7 +101,7 @@ impl EpollEntry {
/// This method returns `None` if the file is dead. Otherwise, it returns the epoll event (if /// This method returns `None` if the file is dead. Otherwise, it returns the epoll event (if
/// any) and a boolean value indicating whether the entry should be kept in the ready list /// any) and a boolean value indicating whether the entry should be kept in the ready list
/// (`true`) or removed from the ready list (`false`). /// (`true`) or removed from the ready list (`false`).
pub fn poll(&self) -> Option<(Option<EpollEvent>, bool)> { pub(super) fn poll(&self) -> Option<(Option<EpollEvent>, bool)> {
let file = self.file()?; let file = self.file()?;
let inner = self.inner.lock(); let inner = self.inner.lock();
@ -139,7 +139,7 @@ impl EpollEntry {
/// Updates the epoll entry by the given event masks and flags. /// Updates the epoll entry by the given event masks and flags.
/// ///
/// This method needs to be called in response to `EpollCtl::Add` and `EpollCtl::Mod`. /// This method needs to be called in response to `EpollCtl::Add` and `EpollCtl::Mod`.
pub fn update(&self, event: EpollEvent, flags: EpollFlags) -> IoEvents { pub(super) fn update(&self, event: EpollEvent, flags: EpollFlags) -> IoEvents {
let file = self.file().unwrap(); let file = self.file().unwrap();
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
@ -155,7 +155,7 @@ impl EpollEntry {
/// Shuts down the epoll entry. /// Shuts down the epoll entry.
/// ///
/// This method needs to be called in response to `EpollCtl::Del`. /// This method needs to be called in response to `EpollCtl::Del`.
pub fn shutdown(&self) { pub(super) fn shutdown(&self) {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
self.observer.reset_enabled(&inner); self.observer.reset_enabled(&inner);
@ -163,40 +163,40 @@ impl EpollEntry {
} }
/// Gets the underlying observer. /// Gets the underlying observer.
pub fn observer(&self) -> &EpollEntryObserver { pub(super) fn observer(&self) -> &EpollEntryObserver {
&self.observer &self.observer
} }
/// Gets the key associated with the epoll entry. /// Gets the key associated with the epoll entry.
pub fn key(&self) -> &EpollEntryKey { pub(super) fn key(&self) -> &EpollEntryKey {
&self.key &self.key
} }
/// Get the file descriptor associated with the epoll entry. /// Gets the file descriptor associated with the epoll entry.
pub fn fd(&self) -> FileDesc { pub(super) fn fd(&self) -> FileDesc {
self.key.fd self.key.fd
} }
/// Get the file associated with this epoll entry. /// Gets the file associated with this epoll entry.
pub fn file_weak(&self) -> &KeyableWeak<dyn FileLike> { pub(super) fn file_weak(&self) -> &KeyableWeak<dyn FileLike> {
&self.key.file &self.key.file
} }
} }
/// A observer for [`EpollEntry`] that can receive events. /// A observer for [`EpollEntry`] that can receive events.
pub struct EpollEntryObserver { pub(super) struct EpollEntryObserver {
// Whether the entry is enabled // Whether the entry is enabled.
is_enabled: AtomicBool, is_enabled: AtomicBool,
// Whether the entry is in the ready list // Whether the entry is in the ready list.
is_ready: AtomicBool, is_ready: AtomicBool,
// The ready set of the epoll file that contains this epoll entry // The ready set of the epoll file that contains this epoll entry.
ready_set: Arc<ReadySet>, ready_set: Arc<ReadySet>,
// The epoll entry itself (always inside an `Arc`) // The epoll entry itself (always inside an `Arc`).
weak_entry: Weak<EpollEntry>, weak_entry: Weak<EpollEntry>,
} }
impl EpollEntryObserver { impl EpollEntryObserver {
pub fn new(ready_set: Arc<ReadySet>, weak_entry: Weak<EpollEntry>) -> Self { fn new(ready_set: Arc<ReadySet>, weak_entry: Weak<EpollEntry>) -> Self {
Self { Self {
is_enabled: AtomicBool::new(false), is_enabled: AtomicBool::new(false),
is_ready: AtomicBool::new(false), is_ready: AtomicBool::new(false),
@ -210,7 +210,7 @@ impl EpollEntryObserver {
/// *Caution:* If this method is called without holding the lock of the ready list, the user /// *Caution:* If this method is called without holding the lock of the ready list, the user
/// must ensure that the behavior is desired with respect to the way the ready list might be /// must ensure that the behavior is desired with respect to the way the ready list might be
/// modified concurrently. /// modified concurrently.
pub fn is_ready(&self) -> bool { fn is_ready(&self) -> bool {
self.is_ready.load(Ordering::Relaxed) self.is_ready.load(Ordering::Relaxed)
} }
@ -219,7 +219,7 @@ impl EpollEntryObserver {
/// This method must be called while holding the lock of the ready list. This is the only way /// This method must be called while holding the lock of the ready list. This is the only way
/// to ensure that the "is ready" state matches the fact that the entry is actually in the /// to ensure that the "is ready" state matches the fact that the entry is actually in the
/// ready list. /// ready list.
pub fn set_ready(&self, _guard: &SpinLockGuard<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>) { fn set_ready(&self, _guard: &SpinLockGuard<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>) {
self.is_ready.store(true, Ordering::Relaxed); self.is_ready.store(true, Ordering::Relaxed);
} }
@ -228,10 +228,7 @@ impl EpollEntryObserver {
/// This method must be called while holding the lock of the ready list. This is the only way /// This method must be called while holding the lock of the ready list. This is the only way
/// to ensure that the "is ready" state matches the fact that the entry is actually in the /// to ensure that the "is ready" state matches the fact that the entry is actually in the
/// ready list. /// ready list.
pub fn reset_ready( fn reset_ready(&self, _guard: &SpinLockGuard<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>) {
&self,
_guard: &SpinLockGuard<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>,
) {
self.is_ready.store(false, Ordering::Relaxed) self.is_ready.store(false, Ordering::Relaxed)
} }
@ -240,7 +237,7 @@ impl EpollEntryObserver {
/// *Caution:* If this method is called without holding the lock of the event masks and flags, /// *Caution:* If this method is called without holding the lock of the event masks and flags,
/// the user must ensure that the behavior is desired with respect to the way the event masks /// the user must ensure that the behavior is desired with respect to the way the event masks
/// and flags might be modified concurrently. /// and flags might be modified concurrently.
pub fn is_enabled(&self) -> bool { fn is_enabled(&self) -> bool {
self.is_enabled.load(Ordering::Relaxed) self.is_enabled.load(Ordering::Relaxed)
} }
@ -263,7 +260,7 @@ impl EpollEntryObserver {
} }
/// Gets an instance of `Weak` that refers to the epoll entry. /// Gets an instance of `Weak` that refers to the epoll entry.
pub fn weak_entry(&self) -> &Weak<EpollEntry> { fn weak_entry(&self) -> &Weak<EpollEntry> {
&self.weak_entry &self.weak_entry
} }
} }
@ -275,7 +272,7 @@ impl Observer<IoEvents> for EpollEntryObserver {
} }
/// A set of ready epoll entries. /// A set of ready epoll entries.
pub struct ReadySet { pub(super) struct ReadySet {
// Entries that are probably ready (having events happened). // Entries that are probably ready (having events happened).
entries: SpinLock<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>, entries: SpinLock<VecDeque<Weak<EpollEntry>>, LocalIrqDisabled>,
// A guard to ensure that ready entries can be popped by one thread at a time. // A guard to ensure that ready entries can be popped by one thread at a time.
@ -287,7 +284,7 @@ pub struct ReadySet {
struct PopGuard; struct PopGuard;
impl ReadySet { impl ReadySet {
pub fn new() -> Self { pub(super) fn new() -> Self {
Self { Self {
entries: SpinLock::new(VecDeque::new()), entries: SpinLock::new(VecDeque::new()),
pop_guard: Mutex::new(PopGuard), pop_guard: Mutex::new(PopGuard),
@ -295,7 +292,7 @@ impl ReadySet {
} }
} }
pub fn push(&self, observer: &EpollEntryObserver) { pub(super) fn push(&self, observer: &EpollEntryObserver) {
// Note that we cannot take the `EpollEntryInner` lock because we are in the callback of // Note that we cannot take the `EpollEntryInner` lock because we are in the callback of
// the event observer. Doing so will cause dead locks due to inconsistent locking orders. // the event observer. Doing so will cause dead locks due to inconsistent locking orders.
// //
@ -322,7 +319,7 @@ impl ReadySet {
self.pollee.add_events(IoEvents::IN); self.pollee.add_events(IoEvents::IN);
} }
pub fn lock_pop(&self) -> ReadySetPopIter { pub(super) fn lock_pop(&self) -> ReadySetPopIter {
ReadySetPopIter { ReadySetPopIter {
ready_set: self, ready_set: self,
_pop_guard: self.pop_guard.lock(), _pop_guard: self.pop_guard.lock(),
@ -330,13 +327,13 @@ impl ReadySet {
} }
} }
pub fn poll(&self, mask: IoEvents, poller: Option<&mut PollHandle>) -> IoEvents { pub(super) fn poll(&self, mask: IoEvents, poller: Option<&mut PollHandle>) -> IoEvents {
self.pollee.poll(mask, poller) self.pollee.poll(mask, poller)
} }
} }
/// An iterator to pop ready entries from a [`ReadySet`]. /// An iterator to pop ready entries from a [`ReadySet`].
pub struct ReadySetPopIter<'a> { pub(super) struct ReadySetPopIter<'a> {
ready_set: &'a ReadySet, ready_set: &'a ReadySet,
_pop_guard: MutexGuard<'a, PopGuard>, _pop_guard: MutexGuard<'a, PopGuard>,
limit: Option<usize>, limit: Option<usize>,

View File

@ -52,7 +52,7 @@ impl EpollFile {
}) })
} }
/// Control the interest list of the epoll file. /// Controls the interest list of the epoll file.
pub fn control(&self, cmd: &EpollCtl) -> Result<()> { pub fn control(&self, cmd: &EpollCtl) -> Result<()> {
let fd = match cmd { let fd = match cmd {
EpollCtl::Add(fd, ..) => *fd, EpollCtl::Add(fd, ..) => *fd,
@ -176,7 +176,7 @@ impl EpollFile {
Ok(()) Ok(())
} }
/// Wait for interesting events happen on the files in the interest list /// Waits for interesting events happen on the files in the interest list
/// of the epoll file. /// of the epoll file.
/// ///
/// This method blocks until either some interesting events happen or /// This method blocks until either some interesting events happen or