[flang-commits] [PATCH] D127316: [flang][runtime] Remove dependency on C++ <mutex> on Windows

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jun 10 04:29:18 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG99fe38a13a2d: [flang][runtime] Remove dependency on C++ <mutex> on Windows (authored by mmuetzel, committed by rovka).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127316/new/

https://reviews.llvm.org/D127316

Files:
  flang/runtime/lock.h


Index: flang/runtime/lock.h
===================================================================
--- flang/runtime/lock.h
+++ flang/runtime/lock.h
@@ -23,6 +23,10 @@
 
 #if USE_PTHREADS
 #include <pthread.h>
+#elif defined(_WIN32)
+// Do not define macros for "min" and "max"
+#define NOMINMAX
+#include <windows.h>
 #else
 #include <mutex>
 #endif
@@ -40,6 +44,12 @@
   }
   bool Try() { return pthread_mutex_trylock(&mutex_) == 0; }
   void Drop() { pthread_mutex_unlock(&mutex_); }
+#elif defined(_WIN32)
+  Lock() { InitializeCriticalSection(&cs_); }
+  ~Lock() { DeleteCriticalSection(&cs_); }
+  void Take() { EnterCriticalSection(&cs_); }
+  bool Try() { return TryEnterCriticalSection(&cs_); }
+  void Drop() { LeaveCriticalSection(&cs_); }
 #else
   void Take() { mutex_.lock(); }
   bool Try() { return mutex_.try_lock(); }
@@ -56,6 +66,8 @@
 private:
 #if USE_PTHREADS
   pthread_mutex_t mutex_{};
+#elif defined(_WIN32)
+  CRITICAL_SECTION cs_;
 #else
   std::mutex mutex_;
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127316.435871.patch
Type: text/x-patch
Size: 993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220610/a9ce4f78/attachment.bin>


More information about the flang-commits mailing list