lib/System/Win32/ThreadLocal.inc: Suppress "unused" warning on -Asserts.
[oota-llvm.git] / lib / System / Win32 / RWMutex.inc
index 08c31f1eb7d2249b0e1ef4b16c1dbf039f935643..e2692269e3a0bf4a1ac7e842d4c03169e8008659 100644 (file)
 
 #include "Win32.h"
 
+// FIXME: Windows does not have reader-writer locks pre-Vista.  If you want
+// real reader-writer locks, you a pthreads implementation for Windows.
+
 namespace llvm {
 using namespace sys;
 
-RWMutex::RWMutex() {
-  data_ = new PSRWLOCK;
-  InitializeSRWLock((PSRWLOCK*)data_);
+RWMutexImpl::RWMutexImpl() {
+  data_ = calloc(1, sizeof(CRITICAL_SECTION));
+  InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
 }
 
-RWMutex::~RWMutex() {
-  delete (PSRWLOCK*)data_;
-  data_ = 0;
+RWMutexImpl::~RWMutexImpl() {
+  DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
+  free(data_);
 }
 
-bool RWMutex::reader_acquire() {
-  AcquireSRWLockShared((PSRWLOCK*)data_);
+bool RWMutexImpl::reader_acquire() {
+  EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::reader_release() {
-  ReleaseSRWLockShared((PSRWLOCK*)data_);
+bool RWMutexImpl::reader_release() {
+  LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::writer_acquire() {
-  AcquireSRWLockExclusive((PSRWLOCK*)data_);
+bool RWMutexImpl::writer_acquire() {
+  EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::writer_release() {
-  ReleaseSRWLockExclusive((PSRWLOCK*)data_);
+bool RWMutexImpl::writer_release() {
+  LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }