[Bf-blender-cvs] [597a9e3246a] tmp-flock: BLI_fileops flock: More fixes.

Bastien Montagne noreply at git.blender.org
Tue Jan 17 17:47:33 CET 2023


Commit: 597a9e3246a6d779dea910328969b7232cd5435d
Author: Bastien Montagne
Date:   Tue Jan 17 17:47:08 2023 +0100
Branches: tmp-flock
https://developer.blender.org/rB597a9e3246a6d779dea910328969b7232cd5435d

BLI_fileops flock: More fixes.

===================================================================

M	source/blender/blenlib/BLI_fileops.h
M	source/blender/blenlib/intern/fileops.c

===================================================================

diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 6c8d3085dd6..45da8765e0b 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -230,7 +230,7 @@ int BLI_access(const char *filepath, int mode) ATTR_WARN_UNUSED_RESULT ATTR_NONN
  * Attempt to lock a file in a shared way (i.e. other shared locks can be acquired on the same file
  * at the same time).
  *
- * \param file_descriptor A file handle as returned e.g. by #BLI_open.
+ * \param file_descriptor A file descriptor as returned e.g. by #BLI_open.
  * \param is_blocking Whether the call should be blocking, or fail and return immediately if the
  *                    lock cannot be acquired.
  * \return true if the file was successfully locked, false otherwise.
@@ -244,11 +244,11 @@ bool BLI_flock_shared(const int file_descriptor, const bool is_blocking);
  */
 bool BLI_flock_exclusive(const int file_descriptor, const bool is_blocking);
 /**
- * Release a lock (either shared or exclusive) previously acquired on the given file handle.
+ * Release a lock (either shared or exclusive) previously acquired on the given file descriptor.
  *
  * This function is never blocking.
  *
- * \param file_descriptor is a file handle as returned e.g. by #BLI_open.
+ * \param file_descriptor A file descriptor as returned e.g. by #BLI_open.
  * \return true is the file was successfully unlocked, false otherwise.
  */
 bool BLI_flock_release(const int file_descriptor);
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index e7b48f53555..a56503ba5cb 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -301,7 +301,7 @@ int BLI_access(const char *filepath, int mode)
 bool BLI_flock_shared(const int file_descriptor, const bool is_blocking)
 {
   OVERLAPPED overlapp_info = {0};
-  return LockFileEx(file_descriptor,
+  return LockFileEx(_get_osfhandle(file_descriptor),
                     (is_blocking ? 0 : LOCKFILE_FAIL_IMMEDIATELY),
                     0,
                     INT_MAX,
@@ -311,7 +311,7 @@ bool BLI_flock_shared(const int file_descriptor, const bool is_blocking)
 bool BLI_flock_exclusive(const int file_descriptor, const bool is_blocking)
 {
   OVERLAPPED overlapp_info = {0};
-  return LockFileEx(file_descriptor,
+  return LockFileEx(_get_osfhandle(file_descriptor),
                     LOCKFILE_EXCLUSIVE_LOCK | (is_blocking ? 0 : LOCKFILE_FAIL_IMMEDIATELY),
                     0,
                     INT_MAX,
@@ -321,7 +321,7 @@ bool BLI_flock_exclusive(const int file_descriptor, const bool is_blocking)
 bool BLI_flock_release(const int file_descriptor)
 {
   OVERLAPPED overlapp_info = {0};
-  return UnlockFile(file_descriptor, 0, 0, INT_MAX, INT_MAX);
+  return UnlockFile(_get_osfhandle(file_descriptor), 0, 0, INT_MAX, INT_MAX);
 }
 
 static bool delete_soft(const wchar_t *path_16, const char **error_message)



More information about the Bf-blender-cvs mailing list