Browse Source

AutoPerThreadSystem: calls [Setup/Cleanup]PerThreadFileSystem()

Tex Riddell 7 years ago
parent
commit
431de81ba9
2 changed files with 7 additions and 3 deletions
  1. 5 1
      include/llvm/Support/FileSystem.h
  2. 2 2
      lib/Support/Windows/MSFileSystem.inc.cpp

+ 5 - 1
include/llvm/Support/FileSystem.h

@@ -53,6 +53,7 @@ namespace fs {
 class MSFileSystem;
 typedef _Inout_ MSFileSystem* MSFileSystemRef;
 
+// Nesting [Setup/Cleanup]PerThreadFileSystem() calls is supported.
 std::error_code SetupPerThreadFileSystem() throw();
 void CleanupPerThreadFileSystem() throw();
 
@@ -78,7 +79,9 @@ private:
   std::error_code ec;
 public:
   AutoPerThreadSystem(_In_ ::llvm::sys::fs::MSFileSystem *value)
-      : m_pOrigValue(::llvm::sys::fs::GetCurrentThreadFileSystem()) {
+      : m_pOrigValue(nullptr) {
+    ::llvm::sys::fs::SetupPerThreadFileSystem();
+    m_pOrigValue = ::llvm::sys::fs::GetCurrentThreadFileSystem();
     SetCurrentThreadFileSystem(nullptr);
     ec = ::llvm::sys::fs::SetCurrentThreadFileSystem(value);
   }
@@ -91,6 +94,7 @@ public:
     } else if (!ec) {
       ::llvm::sys::fs::SetCurrentThreadFileSystem(nullptr);
     }
+    ::llvm::sys::fs::CleanupPerThreadFileSystem();
   }
 
   const std::error_code& error_code() const { return ec; }

+ 2 - 2
lib/Support/Windows/MSFileSystem.inc.cpp

@@ -51,10 +51,10 @@ namespace fs {
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Per-thread MSFileSystem support.
 
-static DWORD g_FileSystemTls;
+static DWORD g_FileSystemTls = 0;
 
 // skip, but keep track of setup/cleanup nesting
-static unsigned g_FileSystemSetupNested = 0;
+static volatile unsigned g_FileSystemSetupNested = 0;
 
 error_code SetupPerThreadFileSystem() throw()
 {