lib/System/Win32/ThreadLocal.inc: Suppress "unused" warning on -Asserts.
[oota-llvm.git] / lib / System / Win32 / RWMutex.inc
index 5360b41b0e65b94217b1f50c1b1b3622b46d5e39..e2692269e3a0bf4a1ac7e842d4c03169e8008659 100644 (file)
 
 #include "Win32.h"
 
-// FIXME: THIS IS NOT THREAD-SAFE!!
-// Windows does not have reader-writer locks pre-Vista.  If you want to have
-// thread-safe LLVM on Windows, for now at least, you need to use a pthreads
-// replacement library.
+// 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() { }
+RWMutexImpl::RWMutexImpl() {
+  data_ = calloc(1, sizeof(CRITICAL_SECTION));
+  InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
+}
 
-RWMutex::~RWMutex() { }
+RWMutexImpl::~RWMutexImpl() {
+  DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
+  free(data_);
+}
 
-bool RWMutex::reader_acquire() {
+bool RWMutexImpl::reader_acquire() {
+  EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::reader_release() {
+bool RWMutexImpl::reader_release() {
+  LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::writer_acquire() {
+bool RWMutexImpl::writer_acquire() {
+  EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }
 
-bool RWMutex::writer_release() {
+bool RWMutexImpl::writer_release() {
+  LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
   return true;
 }