Rollup merge of #136288 - joshtriplett:would-you-could-you-with-some-locks--would-you-could-you-in-some-docs, r=m-ou-se
Improve documentation for file locking Add notes to each method stating that locks get dropped on close. Clarify the return values of the try methods: they're only defined if the lock is held via a *different* file handle/descriptor. That goes along with the documentation that calling them while holding a lock via the *same* file handle/descriptor may deadlock. Document the behavior of unlock if no lock is held. r? `@m-ou-se` (Documentation changes requested in https://github.com/rust-lang/rust/issues/130994 .)
This commit is contained in:
commit
867317835d
1 changed files with 40 additions and 17 deletions
|
@ -629,9 +629,9 @@ impl File {
|
||||||
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
|
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
|
||||||
/// another lock.
|
/// another lock.
|
||||||
///
|
///
|
||||||
/// If this file handle, or a clone of it, already holds an advisory lock the exact behavior is
|
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock the exact
|
||||||
/// unspecified and platform dependent, including the possibility that it will deadlock.
|
/// behavior is unspecified and platform dependent, including the possibility that it will
|
||||||
/// However, if this method returns, then an exclusive lock is held.
|
/// deadlock. However, if this method returns, then an exclusive lock is held.
|
||||||
///
|
///
|
||||||
/// If the file not open for writing, it is unspecified whether this function returns an error.
|
/// If the file not open for writing, it is unspecified whether this function returns an error.
|
||||||
///
|
///
|
||||||
|
@ -639,6 +639,9 @@ impl File {
|
||||||
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
||||||
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
||||||
///
|
///
|
||||||
|
/// The lock will be released when this file (along with any other file descriptors/handles
|
||||||
|
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
|
||||||
|
///
|
||||||
/// # Platform-specific behavior
|
/// # Platform-specific behavior
|
||||||
///
|
///
|
||||||
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` flag,
|
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` flag,
|
||||||
|
@ -671,19 +674,22 @@ impl File {
|
||||||
self.inner.lock()
|
self.inner.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acquire a shared advisory lock on the file. Blocks until the lock can be acquired.
|
/// Acquire a shared (non-exclusive) advisory lock on the file. Blocks until the lock can be acquired.
|
||||||
///
|
///
|
||||||
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
|
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
|
||||||
/// none may hold an exclusive lock.
|
/// none may hold an exclusive lock at the same time.
|
||||||
///
|
///
|
||||||
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
|
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock, the exact
|
||||||
/// unspecified and platform dependent, including the possibility that it will deadlock.
|
/// behavior is unspecified and platform dependent, including the possibility that it will
|
||||||
/// However, if this method returns, then a shared lock is held.
|
/// deadlock. However, if this method returns, then a shared lock is held.
|
||||||
///
|
///
|
||||||
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
|
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
|
||||||
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
||||||
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
||||||
///
|
///
|
||||||
|
/// The lock will be released when this file (along with any other file descriptors/handles
|
||||||
|
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
|
||||||
|
///
|
||||||
/// # Platform-specific behavior
|
/// # Platform-specific behavior
|
||||||
///
|
///
|
||||||
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` flag,
|
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` flag,
|
||||||
|
@ -716,14 +722,18 @@ impl File {
|
||||||
self.inner.lock_shared()
|
self.inner.lock_shared()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acquire an exclusive advisory lock on the file. Returns `Ok(false)` if the file is locked.
|
/// Try to acquire an exclusive advisory lock on the file.
|
||||||
|
///
|
||||||
|
/// Returns `Ok(false)` if a different lock is already held on this file (via another
|
||||||
|
/// handle/descriptor).
|
||||||
///
|
///
|
||||||
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
|
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
|
||||||
/// another lock.
|
/// another lock.
|
||||||
///
|
///
|
||||||
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
|
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock, the exact
|
||||||
/// unspecified and platform dependent, including the possibility that it will deadlock.
|
/// behavior is unspecified and platform dependent, including the possibility that it will
|
||||||
/// However, if this method returns, then an exclusive lock is held.
|
/// deadlock. However, if this method returns `Ok(true)`, then it has acquired an exclusive
|
||||||
|
/// lock.
|
||||||
///
|
///
|
||||||
/// If the file not open for writing, it is unspecified whether this function returns an error.
|
/// If the file not open for writing, it is unspecified whether this function returns an error.
|
||||||
///
|
///
|
||||||
|
@ -731,6 +741,9 @@ impl File {
|
||||||
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
||||||
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
||||||
///
|
///
|
||||||
|
/// The lock will be released when this file (along with any other file descriptors/handles
|
||||||
|
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
|
||||||
|
///
|
||||||
/// # Platform-specific behavior
|
/// # Platform-specific behavior
|
||||||
///
|
///
|
||||||
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` and
|
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` and
|
||||||
|
@ -764,20 +777,25 @@ impl File {
|
||||||
self.inner.try_lock()
|
self.inner.try_lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acquire a shared advisory lock on the file.
|
/// Try to acquire a shared (non-exclusive) advisory lock on the file.
|
||||||
/// Returns `Ok(false)` if the file is exclusively locked.
|
///
|
||||||
|
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
|
||||||
|
/// handle/descriptor).
|
||||||
///
|
///
|
||||||
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
|
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
|
||||||
/// none may hold an exclusive lock.
|
/// none may hold an exclusive lock at the same time.
|
||||||
///
|
///
|
||||||
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
|
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
|
||||||
/// unspecified and platform dependent, including the possibility that it will deadlock.
|
/// unspecified and platform dependent, including the possibility that it will deadlock.
|
||||||
/// However, if this method returns, then a shared lock is held.
|
/// However, if this method returns `Ok(true)`, then it has acquired a shared lock.
|
||||||
///
|
///
|
||||||
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
|
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
|
||||||
/// [`try_lock`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
/// [`try_lock`], and [`unlock`]. Its interactions with other methods, such as [`read`]
|
||||||
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
|
||||||
///
|
///
|
||||||
|
/// The lock will be released when this file (along with any other file descriptors/handles
|
||||||
|
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
|
||||||
|
///
|
||||||
/// # Platform-specific behavior
|
/// # Platform-specific behavior
|
||||||
///
|
///
|
||||||
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` and
|
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` and
|
||||||
|
@ -813,7 +831,12 @@ impl File {
|
||||||
|
|
||||||
/// Release all locks on the file.
|
/// Release all locks on the file.
|
||||||
///
|
///
|
||||||
/// All remaining locks are released when the file handle, and all clones of it, are dropped.
|
/// All locks are released when the file (along with any other file descriptors/handles
|
||||||
|
/// duplicated or inherited from it) is closed. This method allows releasing locks without
|
||||||
|
/// closing the file.
|
||||||
|
///
|
||||||
|
/// If no lock is currently held via this file descriptor/handle, this method may return an
|
||||||
|
/// error, or may return successfully without taking any action.
|
||||||
///
|
///
|
||||||
/// # Platform-specific behavior
|
/// # Platform-specific behavior
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue