RegisterPressure: Expose RegisterOperands API
[oota-llvm.git] / include / llvm / Support / Mutex.h
index f340051361b0fbee7d1f01a3e12a488b3f50bb8e..0f4e61af443950ffae66722981302a7641ae793a 100644 (file)
 #define LLVM_SUPPORT_MUTEX_H
 
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Threading.h"
 #include <cassert>
 
 namespace llvm
 {
-  // Forward declare this function.
-  bool llvm_is_multithreaded();
-
   namespace sys
   {
     /// @brief Platform agnostic Mutex class.
@@ -72,14 +70,16 @@ namespace llvm
     /// @name Platform Dependent Data
     /// @{
     private:
+#if defined(LLVM_ENABLE_THREADS) && LLVM_ENABLE_THREADS != 0
       void* data_; ///< We don't know what the data will be
+#endif
 
     /// @}
     /// @name Do Not Implement
     /// @{
     private:
-      MutexImpl(const MutexImpl &) LLVM_DELETED_FUNCTION;
-      void operator=(const MutexImpl &) LLVM_DELETED_FUNCTION;
+      MutexImpl(const MutexImpl &) = delete;
+      void operator=(const MutexImpl &) = delete;
     /// @}
     };
 
@@ -88,16 +88,17 @@ namespace llvm
     /// indicates whether this mutex should become a no-op when we're not
     /// running in multithreaded mode.
     template<bool mt_only>
-    class SmartMutex : public MutexImpl {
+    class SmartMutex {
+      MutexImpl impl;
       unsigned acquired;
       bool recursive;
     public:
       explicit SmartMutex(bool rec = true) :
-        MutexImpl(rec), acquired(0), recursive(rec) { }
+        impl(rec), acquired(0), recursive(rec) { }
 
-      bool acquire() {
+      bool lock() {
         if (!mt_only || llvm_is_multithreaded()) {
-          return MutexImpl::acquire();
+          return impl.acquire();
         } else {
           // Single-threaded debugging code.  This would be racy in
           // multithreaded mode, but provides not sanity checks in single
@@ -108,9 +109,9 @@ namespace llvm
         }
       }
 
-      bool release() {
+      bool unlock() {
         if (!mt_only || llvm_is_multithreaded()) {
-          return MutexImpl::release();
+          return impl.release();
         } else {
           // Single-threaded debugging code.  This would be racy in
           // multithreaded mode, but provides not sanity checks in single
@@ -122,9 +123,9 @@ namespace llvm
         }
       }
 
-      bool tryacquire() {
+      bool try_lock() {
         if (!mt_only || llvm_is_multithreaded())
-          return MutexImpl::tryacquire();
+          return impl.tryacquire();
         else return true;
       }
 
@@ -142,11 +143,11 @@ namespace llvm
 
     public:
       SmartScopedLock(SmartMutex<mt_only>& m) : mtx(m) {
-        mtx.acquire();
+        mtx.lock();
       }
 
       ~SmartScopedLock() {
-        mtx.release();
+        mtx.unlock();
       }
     };