Index: flang/runtime/lock.h =================================================================== --- flang/runtime/lock.h +++ flang/runtime/lock.h @@ -15,23 +15,19 @@ // Avoid if possible to avoid introduction of C++ runtime // library dependence. -#ifndef _WIN32 -#define USE_PTHREADS 1 +#ifdef _WIN32 +// Do not define macros for "min" and "max" +#define NOMINMAX +#include #else -#undef USE_PTHREADS -#endif - -#if USE_PTHREADS #include -#else -#include #endif namespace Fortran::runtime { class Lock { public: -#if USE_PTHREADS +#ifndef _WIN32 Lock() { pthread_mutex_init(&mutex_, nullptr); } ~Lock() { pthread_mutex_destroy(&mutex_); } void Take() { @@ -41,9 +37,11 @@ bool Try() { return pthread_mutex_trylock(&mutex_) == 0; } void Drop() { pthread_mutex_unlock(&mutex_); } #else - void Take() { mutex_.lock(); } - bool Try() { return mutex_.try_lock(); } - void Drop() { mutex_.unlock(); } + Lock() { InitializeCriticalSection(&cs_); } + ~Lock() { DeleteCriticalSection(&cs_); } + void Take() { EnterCriticalSection(&cs_); } + bool Try() { return TryEnterCriticalSection(&cs_); } + void Drop() { LeaveCriticalSection(&cs_); } #endif void CheckLocked(const Terminator &terminator) { @@ -54,10 +52,10 @@ } private: -#if USE_PTHREADS +#ifndef _WIN32 pthread_mutex_t mutex_{}; #else - std::mutex mutex_; + CRITICAL_SECTION cs_; #endif };