diff options
| -rw-r--r-- | source/core/slang-io.cpp | 17 | ||||
| -rw-r--r-- | tools/slang-unit-test/unit-test-lock-file.cpp | 6 |
2 files changed, 21 insertions, 2 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 851c70073..0720e788f 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -1316,9 +1316,17 @@ void LockFile::close() return; #if SLANG_WINDOWS_FAMILY - ::CloseHandle(m_fileHandle); + if (m_fileHandle != INVALID_HANDLE_VALUE) + { + ::CloseHandle(m_fileHandle); + m_fileHandle = INVALID_HANDLE_VALUE; + } #else - ::close(m_fileHandle); + if (m_fileHandle != -1) + { + ::close(m_fileHandle); + m_fileHandle = -1; + } #endif m_isOpen = false; @@ -1409,6 +1417,11 @@ SlangResult LockFile::unlock() LockFile::LockFile() : m_isOpen(false) { +#if SLANG_WINDOWS_FAMILY + m_fileHandle = INVALID_HANDLE_VALUE; +#else + m_fileHandle = -1; +#endif } LockFile::~LockFile() diff --git a/tools/slang-unit-test/unit-test-lock-file.cpp b/tools/slang-unit-test/unit-test-lock-file.cpp index 6458d4b5f..6f1e0b6b8 100644 --- a/tools/slang-unit-test/unit-test-lock-file.cpp +++ b/tools/slang-unit-test/unit-test-lock-file.cpp @@ -37,11 +37,17 @@ SLANG_UNIT_TEST(lockFileSync) SLANG_IGNORE_TEST #endif + // Clean up any leftover lock file from previous runs + File::remove(fileName); + // Test using multiple threads. { static std::atomic<uint32_t> lockCounter; static std::atomic<uint32_t> unlockCounter; + lockCounter = 0; + unlockCounter = 0; + struct LockTask { std::thread thread; |
