@@ -629,16 +629,19 @@ impl File {
629
629
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
630
630
/// another lock.
631
631
///
632
- /// If this file handle, or a clone of it, already holds an advisory lock the exact behavior is
633
- /// unspecified and platform dependent, including the possibility that it will deadlock.
634
- /// However, if this method returns, then an exclusive lock is held.
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.
635
635
///
636
636
/// If the file not open for writing, it is unspecified whether this function returns an error.
637
637
///
638
638
/// Note, this is an advisory lock meant to interact with [`lock_shared`], [`try_lock`],
639
639
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
640
640
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
641
641
///
642
+ /// The lock will be released when this file (along with any other file descriptors/handles
643
+ /// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
644
+ ///
642
645
/// # Platform-specific behavior
643
646
///
644
647
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` flag,
@@ -671,19 +674,22 @@ impl File {
671
674
self . inner . lock ( )
672
675
}
673
676
674
- /// Acquire a shared advisory lock on the file. Blocks until the lock can be acquired.
677
+ /// Acquire a shared (non-exclusive) advisory lock on the file. Blocks until the lock can be acquired.
675
678
///
676
679
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
677
- /// none may hold an exclusive lock.
680
+ /// none may hold an exclusive lock at the same time .
678
681
///
679
- /// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
680
- /// unspecified and platform dependent, including the possibility that it will deadlock.
681
- /// However, if this method returns, then a shared lock is held.
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.
682
685
///
683
686
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
684
687
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
685
688
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
686
689
///
690
+ /// The lock will be released when this file (along with any other file descriptors/handles
691
+ /// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
692
+ ///
687
693
/// # Platform-specific behavior
688
694
///
689
695
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` flag,
@@ -716,21 +722,28 @@ impl File {
716
722
self . inner . lock_shared ( )
717
723
}
718
724
719
- /// Acquire an exclusive advisory lock on the file. Returns `Ok(false)` if the file is locked.
725
+ /// Try to acquire an exclusive advisory lock on the file.
726
+ ///
727
+ /// Returns `Ok(false)` if a different lock is already held on this file (via another
728
+ /// handle/descriptor).
720
729
///
721
730
/// This acquires an exclusive advisory lock; no other file handle to this file may acquire
722
731
/// another lock.
723
732
///
724
- /// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
725
- /// unspecified and platform dependent, including the possibility that it will deadlock.
726
- /// However, if this method returns, then an exclusive lock is held.
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.
727
737
///
728
738
/// If the file not open for writing, it is unspecified whether this function returns an error.
729
739
///
730
740
/// Note, this is an advisory lock meant to interact with [`lock`], [`lock_shared`],
731
741
/// [`try_lock_shared`], and [`unlock`]. Its interactions with other methods, such as [`read`]
732
742
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
733
743
///
744
+ /// The lock will be released when this file (along with any other file descriptors/handles
745
+ /// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
746
+ ///
734
747
/// # Platform-specific behavior
735
748
///
736
749
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` and
@@ -764,20 +777,25 @@ impl File {
764
777
self . inner . try_lock ( )
765
778
}
766
779
767
- /// Acquire a shared advisory lock on the file.
768
- /// Returns `Ok(false)` if the file is exclusively locked.
780
+ /// Try to acquire a shared (non-exclusive) advisory lock on the file.
781
+ ///
782
+ /// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
783
+ /// handle/descriptor).
769
784
///
770
785
/// This acquires a shared advisory lock; more than one file handle may hold a shared lock, but
771
- /// none may hold an exclusive lock.
786
+ /// none may hold an exclusive lock at the same time .
772
787
///
773
788
/// If this file handle, or a clone of it, already holds an advisory lock, the exact behavior is
774
789
/// unspecified and platform dependent, including the possibility that it will deadlock.
775
- /// However, if this method returns, then a shared lock is held .
790
+ /// However, if this method returns `Ok(true)` , then it has acquired a shared lock.
776
791
///
777
792
/// Note, this is an advisory lock meant to interact with [`lock`], [`try_lock`],
778
793
/// [`try_lock`], and [`unlock`]. Its interactions with other methods, such as [`read`]
779
794
/// and [`write`] are platform specific, and it may or may not cause non-lockholders to block.
780
795
///
796
+ /// The lock will be released when this file (along with any other file descriptors/handles
797
+ /// duplicated or inherited from it) is closed, or if the [`unlock`] method is called.
798
+ ///
781
799
/// # Platform-specific behavior
782
800
///
783
801
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_SH` and
@@ -813,7 +831,12 @@ impl File {
813
831
814
832
/// Release all locks on the file.
815
833
///
816
- /// All remaining locks are released when the file handle, and all clones of it, are dropped.
834
+ /// All locks are released when the file (along with any other file descriptors/handles
835
+ /// duplicated or inherited from it) is closed. This method allows releasing locks without
836
+ /// closing the file.
837
+ ///
838
+ /// If no lock is currently held via this file descriptor/handle, this method may return an
839
+ /// error, or may return successfully without taking any action.
817
840
///
818
841
/// # Platform-specific behavior
819
842
///
0 commit comments