System/Path/Windows: Change GetRootDirectory to return file:/// instead of C:/.
[oota-llvm.git] / lib / System / RWMutex.cpp
index a781a379ed418480d2fefcdfed24947e2e64f514..deb04709d829c6e5c2910ea336e2d6a214052603 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/Config/config.h"
 #include "llvm/System/RWMutex.h"
+#include <cstring>
 
 //===----------------------------------------------------------------------===//
 //=== WARNING: Implementation here must contain only TRULY operating system
 // Define all methods as no-ops if threading is explicitly disabled
 namespace llvm {
 using namespace sys;
-RWMutex::RWMutex( bool recursive) { }
-RWMutex::~RWMutex() { }
-bool RWMutex::reader_acquire() { return true; }
-bool RWMutex::reader_release() { return true; }
-bool RWMutex::writer_acquire() { return true; }
-bool RWMutex::writer_release() { return true; }
+RWMutexImpl::RWMutexImpl() { }
+RWMutexImpl::~RWMutexImpl() { }
+bool RWMutexImpl::reader_acquire() { return true; }
+bool RWMutexImpl::reader_release() { return true; }
+bool RWMutexImpl::writer_acquire() { return true; }
+bool RWMutexImpl::writer_release() { return true; }
 }
 #else
 
@@ -56,7 +57,7 @@ using namespace sys;
 static const bool pthread_enabled = true;
 
 // Construct a RWMutex using pthread calls
-RWMutex::RWMutex()
+RWMutexImpl::RWMutexImpl()
   : data_(0)
 {
   if (pthread_enabled)
@@ -64,23 +65,15 @@ RWMutex::RWMutex()
     // Declare the pthread_rwlock data structures
     pthread_rwlock_t* rwlock =
       static_cast<pthread_rwlock_t*>(malloc(sizeof(pthread_rwlock_t)));
-    pthread_rwlockattr_t attr;
 
-    // Initialize the rwlock attributes
-    int errorcode = pthread_rwlockattr_init(&attr);
-    assert(errorcode == 0);
-
-#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
-    // Make it a process local rwlock
-    errorcode = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
+#ifdef __APPLE__
+    // Workaround a bug/mis-feature in Darwin's pthread_rwlock_init.
+    bzero(rwlock, sizeof(pthread_rwlock_t));
 #endif
 
     // Initialize the rwlock
-    errorcode = pthread_rwlock_init(rwlock, &attr);
-    assert(errorcode == 0);
-
-    // Destroy the attributes
-    errorcode = pthread_rwlockattr_destroy(&attr);
+    int errorcode = pthread_rwlock_init(rwlock, NULL);
+    (void)errorcode;
     assert(errorcode == 0);
 
     // Assign the data member
@@ -89,7 +82,7 @@ RWMutex::RWMutex()
 }
 
 // Destruct a RWMutex
-RWMutex::~RWMutex()
+RWMutexImpl::~RWMutexImpl()
 {
   if (pthread_enabled)
   {
@@ -101,7 +94,7 @@ RWMutex::~RWMutex()
 }
 
 bool
-RWMutex::reader_acquire()
+RWMutexImpl::reader_acquire()
 {
   if (pthread_enabled)
   {
@@ -110,12 +103,11 @@ RWMutex::reader_acquire()
 
     int errorcode = pthread_rwlock_rdlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
-RWMutex::reader_release()
+RWMutexImpl::reader_release()
 {
   if (pthread_enabled)
   {
@@ -124,12 +116,11 @@ RWMutex::reader_release()
 
     int errorcode = pthread_rwlock_unlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
-RWMutex::writer_acquire()
+RWMutexImpl::writer_acquire()
 {
   if (pthread_enabled)
   {
@@ -138,12 +129,11 @@ RWMutex::writer_acquire()
 
     int errorcode = pthread_rwlock_wrlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
-RWMutex::writer_release()
+RWMutexImpl::writer_release()
 {
   if (pthread_enabled)
   {
@@ -152,8 +142,7 @@ RWMutex::writer_release()
 
     int errorcode = pthread_rwlock_unlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 }
@@ -166,4 +155,3 @@ RWMutex::writer_release()
 #warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 was set in System/Mutex.cpp
 #endif
 #endif
-