|
@@ -85,14 +85,15 @@ namespace llvm
|
|
|
/// indicates whether this mutex should become a no-op when we're not
|
|
|
/// running in multithreaded mode.
|
|
|
template<bool mt_only>
|
|
|
- class SmartRWMutex : public RWMutexImpl {
|
|
|
+ class SmartRWMutex {
|
|
|
+ RWMutexImpl impl;
|
|
|
unsigned readers, writers;
|
|
|
public:
|
|
|
- explicit SmartRWMutex() : RWMutexImpl(), readers(0), writers(0) { }
|
|
|
+ explicit SmartRWMutex() : impl(), readers(0), writers(0) { }
|
|
|
|
|
|
- bool reader_acquire() {
|
|
|
+ bool lock_shared() {
|
|
|
if (!mt_only || llvm_is_multithreaded())
|
|
|
- return RWMutexImpl::reader_acquire();
|
|
|
+ return impl.reader_acquire();
|
|
|
|
|
|
// Single-threaded debugging code. This would be racy in multithreaded
|
|
|
// mode, but provides not sanity checks in single threaded mode.
|
|
@@ -100,9 +101,9 @@ namespace llvm
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- bool reader_release() {
|
|
|
+ bool unlock_shared() {
|
|
|
if (!mt_only || llvm_is_multithreaded())
|
|
|
- return RWMutexImpl::reader_release();
|
|
|
+ return impl.reader_release();
|
|
|
|
|
|
// Single-threaded debugging code. This would be racy in multithreaded
|
|
|
// mode, but provides not sanity checks in single threaded mode.
|
|
@@ -111,9 +112,9 @@ namespace llvm
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- bool writer_acquire() {
|
|
|
+ bool lock() {
|
|
|
if (!mt_only || llvm_is_multithreaded())
|
|
|
- return RWMutexImpl::writer_acquire();
|
|
|
+ return impl.writer_acquire();
|
|
|
|
|
|
// Single-threaded debugging code. This would be racy in multithreaded
|
|
|
// mode, but provides not sanity checks in single threaded mode.
|
|
@@ -122,9 +123,9 @@ namespace llvm
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- bool writer_release() {
|
|
|
+ bool unlock() {
|
|
|
if (!mt_only || llvm_is_multithreaded())
|
|
|
- return RWMutexImpl::writer_release();
|
|
|
+ return impl.writer_release();
|
|
|
|
|
|
// Single-threaded debugging code. This would be racy in multithreaded
|
|
|
// mode, but provides not sanity checks in single threaded mode.
|
|
@@ -145,11 +146,11 @@ namespace llvm
|
|
|
SmartRWMutex<mt_only>& mutex;
|
|
|
|
|
|
explicit SmartScopedReader(SmartRWMutex<mt_only>& m) : mutex(m) {
|
|
|
- mutex.reader_acquire();
|
|
|
+ mutex.lock_shared();
|
|
|
}
|
|
|
|
|
|
~SmartScopedReader() {
|
|
|
- mutex.reader_release();
|
|
|
+ mutex.unlock_shared();
|
|
|
}
|
|
|
};
|
|
|
typedef SmartScopedReader<false> ScopedReader;
|
|
@@ -160,11 +161,11 @@ namespace llvm
|
|
|
SmartRWMutex<mt_only>& mutex;
|
|
|
|
|
|
explicit SmartScopedWriter(SmartRWMutex<mt_only>& m) : mutex(m) {
|
|
|
- mutex.writer_acquire();
|
|
|
+ mutex.lock();
|
|
|
}
|
|
|
|
|
|
~SmartScopedWriter() {
|
|
|
- mutex.writer_release();
|
|
|
+ mutex.unlock();
|
|
|
}
|
|
|
};
|
|
|
typedef SmartScopedWriter<false> ScopedWriter;
|