aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/System
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-18 17:53:17 +0000
committerOwen Anderson <resistor@mac.com>2009-06-18 17:53:17 +0000
commitb849a4dd4bee9ad17e295691087ce09e8d77d685 (patch)
treed8db21f0b4ae2c14aefdc587b06368c5278620bd /include/llvm/System
parente53118ea32370b5c57c61ae5e8125883acfb641b (diff)
downloadexternal_llvm-b849a4dd4bee9ad17e295691087ce09e8d77d685.zip
external_llvm-b849a4dd4bee9ad17e295691087ce09e8d77d685.tar.gz
external_llvm-b849a4dd4bee9ad17e295691087ce09e8d77d685.tar.bz2
Insert a SmartMutex templated class into the class hierarchy, which takes a template parameter specifying whether this mutex
should become a no-op when not running in multithreaded mode. Make sys::Mutex a typedef of SmartMutex<false>, to preserve source compatibility. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System')
-rw-r--r--include/llvm/System/Mutex.h48
1 files changed, 43 insertions, 5 deletions
diff --git a/include/llvm/System/Mutex.h b/include/llvm/System/Mutex.h
index 4f38493..f749c5d 100644
--- a/include/llvm/System/Mutex.h
+++ b/include/llvm/System/Mutex.h
@@ -14,12 +14,14 @@
#ifndef LLVM_SYSTEM_MUTEX_H
#define LLVM_SYSTEM_MUTEX_H
+#include "llvm/System/Threading.h"
+
namespace llvm
{
namespace sys
{
/// @brief Platform agnostic Mutex class.
- class Mutex
+ class MutexImpl
{
/// @name Constructors
/// @{
@@ -30,11 +32,11 @@ namespace llvm
/// also more likely to deadlock (same thread can't acquire more than
/// once).
/// @brief Default Constructor.
- explicit Mutex(bool recursive = true);
+ explicit MutexImpl(bool recursive = true);
/// Releases and removes the lock
/// @brief Destructor
- ~Mutex();
+ ~MutexImpl();
/// @}
/// @name Methods
@@ -74,10 +76,46 @@ namespace llvm
/// @name Do Not Implement
/// @{
private:
- Mutex(const Mutex & original);
- void operator=(const Mutex &);
+ MutexImpl(const MutexImpl & original);
+ void operator=(const MutexImpl &);
/// @}
};
+
+
+ /// SmartMutex - A mutex with a compile time constant parameter that
+ /// indicates whether this mutex should become a no-op when we're not
+ /// running in multithreaded mode.
+ template<bool mt_only>
+ class SmartMutex {
+ MutexImpl mtx;
+ public:
+ explicit SmartMutex(bool recursive = true) : mtx(recursive) { }
+
+ bool acquire() {
+ if (!mt_only || (mt_only && llvm_is_multithreaded()))
+ return mtx.acquire();
+ return true;
+ }
+
+ bool release() {
+ if (!mt_only || (mt_only && llvm_is_multithreaded()))
+ return mtx.release();
+ return true;
+ }
+
+ bool tryacquire() {
+ if (!mt_only || (mt_only && llvm_is_multithreaded()))
+ return mtx.tryacquire();
+ return true;
+ }
+
+ private:
+ SmartMutex<mt_only>(const SmartMutex<mt_only> & original);
+ void operator=(const SmartMutex<mt_only> &);
+ };
+
+ /// Mutex - A standard, always enforced mutex.
+ typedef SmartMutex<false> Mutex;
}
}