Skip to content

Commit 168693d

Browse files
committed
Reword file lock documentation to clarify advisory vs mandatory
Remove the word "advisory", and make it more explicit that the lock may be advisory or mandatory depending on platform.
1 parent aae7e6c commit 168693d

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

std/src/fs.rs

+40-35
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,20 @@ impl File {
624624
self.inner.datasync()
625625
}
626626

627-
/// Acquire an exclusive advisory lock on the file. Blocks until the lock can be acquired.
627+
/// Acquire an exclusive lock on the file. Blocks until the lock can be acquired.
628628
///
629-
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
630-
/// another lock.
629+
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
631630
///
632-
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock the exact
633-
/// behavior is unspecified and platform dependent, including the possibility that it will
634-
/// deadlock. However, if this method returns, then an exclusive lock is held.
631+
/// If this file handle/descriptor, or a clone of it, already holds an lock the exact behavior
632+
/// is unspecified and platform dependent, including the possibility that it will deadlock.
633+
/// However, if this method returns, then an exclusive lock is held.
635634
///
636635
/// If the file not open for writing, it is unspecified whether this function returns an error.
637636
///
638-
/// Note, this is an advisory lock meant to interact with [`lock_shared`], [`try_lock`],
639-
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
640-
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
637+
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
638+
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
639+
/// other methods, such as [`read`] and [`write`] are platform specific, and it may or may not
640+
/// cause non-lockholders to block.
641641
///
642642
/// The lock will be released when this file (along with any other file descriptors/handles
643643
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
@@ -650,6 +650,7 @@ impl File {
650650
///
651651
/// [changes]: io#platform-specific-behavior
652652
///
653+
/// [`lock`]: File::lock
653654
/// [`lock_shared`]: File::lock_shared
654655
/// [`try_lock`]: File::try_lock
655656
/// [`try_lock_shared`]: File::try_lock_shared
@@ -674,18 +675,19 @@ impl File {
674675
self.inner.lock()
675676
}
676677

677-
/// Acquire a shared (non-exclusive) advisory lock on the file. Blocks until the lock can be acquired.
678+
/// Acquire a shared (non-exclusive) lock on the file. Blocks until the lock can be acquired.
678679
///
679-
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
680-
/// none may hold an exclusive lock at the same time.
680+
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
681+
/// hold an exclusive lock at the same time.
681682
///
682-
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock, the exact
683-
/// behavior is unspecified and platform dependent, including the possibility that it will
684-
/// deadlock. However, if this method returns, then a shared lock is held.
683+
/// If this file handle/descriptor, or a clone of it, already holds an lock, the exact behavior
684+
/// is unspecified and platform dependent, including the possibility that it will deadlock.
685+
/// However, if this method returns, then a shared lock is held.
685686
///
686-
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
687-
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
688-
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
687+
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
688+
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
689+
/// other methods, such as [`read`] and [`write`] are platform specific, and it may or may not
690+
/// cause non-lockholders to block.
689691
///
690692
/// The lock will be released when this file (along with any other file descriptors/handles
691693
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
@@ -699,6 +701,7 @@ impl File {
699701
/// [changes]: io#platform-specific-behavior
700702
///
701703
/// [`lock`]: File::lock
704+
/// [`lock_shared`]: File::lock_shared
702705
/// [`try_lock`]: File::try_lock
703706
/// [`try_lock_shared`]: File::try_lock_shared
704707
/// [`unlock`]: File::unlock
@@ -722,24 +725,23 @@ impl File {
722725
self.inner.lock_shared()
723726
}
724727

725-
/// Try to acquire an exclusive advisory lock on the file.
728+
/// Try to acquire an exclusive lock on the file.
726729
///
727730
/// Returns `Ok(false)` if a different lock is already held on this file (via another
728731
/// handle/descriptor).
729732
///
730-
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
731-
/// another lock.
733+
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
732734
///
733-
/// If this file handle/descriptor, or a clone of it, already holds an advisory lock, the exact
734-
/// behavior is unspecified and platform dependent, including the possibility that it will
735-
/// deadlock. However, if this method returns `Ok(true)`, then it has acquired an exclusive
736-
/// lock.
735+
/// If this file handle/descriptor, or a clone of it, already holds an lock, the exact behavior
736+
/// is unspecified and platform dependent, including the possibility that it will deadlock.
737+
/// However, if this method returns `Ok(true)`, then it has acquired an exclusive lock.
737738
///
738739
/// If the file not open for writing, it is unspecified whether this function returns an error.
739740
///
740-
/// Note, this is an advisory lock meant to interact with [`lock`], [`lock_shared`],
741-
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
742-
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
741+
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
742+
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
743+
/// other methods, such as [`read`] and [`write`] are platform specific, and it may or may not
744+
/// cause non-lockholders to block.
743745
///
744746
/// The lock will be released when this file (along with any other file descriptors/handles
745747
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
@@ -755,6 +757,7 @@ impl File {
755757
///
756758
/// [`lock`]: File::lock
757759
/// [`lock_shared`]: File::lock_shared
760+
/// [`try_lock`]: File::try_lock
758761
/// [`try_lock_shared`]: File::try_lock_shared
759762
/// [`unlock`]: File::unlock
760763
/// [`read`]: Read::read
@@ -777,21 +780,22 @@ impl File {
777780
self.inner.try_lock()
778781
}
779782

780-
/// Try to acquire a shared (non-exclusive) advisory lock on the file.
783+
/// Try to acquire a shared (non-exclusive) lock on the file.
781784
///
782785
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
783786
/// handle/descriptor).
784787
///
785-
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
786-
/// none may hold an exclusive lock at the same time.
788+
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
789+
/// hold an exclusive lock at the same time.
787790
///
788-
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
791+
/// If this file handle, or a clone of it, already holds an lock, the exact behavior is
789792
/// unspecified and platform dependent, including the possibility that it will deadlock.
790793
/// However, if this method returns `Ok(true)`, then it has acquired a shared lock.
791794
///
792-
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
793-
/// [`try_lock`], and [`unlock`]. Its interactions with other methods, such as [`read`]
794-
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
795+
/// This lock may be advisory or mandatory. This lock is meant to interact with [`lock`],
796+
/// [`try_lock`], [`lock_shared`], [`try_lock_shared`], and [`unlock`]. Its interactions with
797+
/// other methods, such as [`read`] and [`write`] are platform specific, and it may or may not
798+
/// cause non-lockholders to block.
795799
///
796800
/// The lock will be released when this file (along with any other file descriptors/handles
797801
/// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
@@ -808,6 +812,7 @@ impl File {
808812
/// [`lock`]: File::lock
809813
/// [`lock_shared`]: File::lock_shared
810814
/// [`try_lock`]: File::try_lock
815+
/// [`try_lock_shared`]: File::try_lock_shared
811816
/// [`unlock`]: File::unlock
812817
/// [`read`]: Read::read
813818
/// [`write`]: Write::write

0 commit comments

Comments
 (0)