System/Path/Windows: Change GetRootDirectory to return file:/// instead of C:/.
[oota-llvm.git] / lib / System / RWMutex.cpp
index cf1aea03ddf3e51e879dfe92b11b87eedc376a10..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
@@ -64,23 +65,15 @@ RWMutexImpl::RWMutexImpl()
     // 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
@@ -110,8 +103,7 @@ RWMutexImpl::reader_acquire()
 
     int errorcode = pthread_rwlock_rdlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
@@ -124,8 +116,7 @@ RWMutexImpl::reader_release()
 
     int errorcode = pthread_rwlock_unlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
@@ -138,8 +129,7 @@ RWMutexImpl::writer_acquire()
 
     int errorcode = pthread_rwlock_wrlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 bool
@@ -152,8 +142,7 @@ RWMutexImpl::writer_release()
 
     int errorcode = pthread_rwlock_unlock(rwlock);
     return errorcode == 0;
-  }
-  return false;
+  } else return false;
 }
 
 }