Change File::try_lock() and try_lock_shared() to return io::Result<()> by cberner · Pull Request #140718 · rust-lang/rust (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisDenton ah, thanks for flagging that. I have very little experience with the Windows platform, so I appreciate the help!
The LockFileEx documentation says:
The LockFileEx function operates asynchronously if the file handle was opened for asynchronous I/O, unless the LOCKFILE_FAIL_IMMEDIATELY flag is specified. If an exclusive lock is requested for a range of a file that already has a shared or exclusive lock, the function returns the error ERROR_IO_PENDING.
and I interpreted that to mean that when LOCKFILE_FAIL_IMMEDIATELY
is specified, then waiting on the event is unnecessary. But am I misreading that, and we need the same event waiting code that's in acquire_lock()
in the try_lock()
/try_lock_shared()
functions?