[llvm-commits] [compiler-rt] r159438 - in /compiler-rt/trunk/lib: asan/asan_lock.h sanitizer_common/sanitizer_mutex.h tsan/rtl/tsan_mutex.cc tsan/rtl/tsan_mutex.h
Dmitry Vyukov
dvyukov at google.com
Fri Jun 29 10:10:08 PDT 2012
Author: dvyukov
Date: Fri Jun 29 12:10:08 2012
New Revision: 159438
URL: http://llvm.org/viewvc/llvm-project?rev=159438&view=rev
Log:
tsan/asan: unify ScopedLock
Added:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h (with props)
Modified:
compiler-rt/trunk/lib/asan/asan_lock.h
compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h
Modified: compiler-rt/trunk/lib/asan/asan_lock.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_lock.h?rev=159438&r1=159437&r2=159438&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_lock.h (original)
+++ compiler-rt/trunk/lib/asan/asan_lock.h Fri Jun 29 12:10:08 2012
@@ -14,6 +14,7 @@
#ifndef ASAN_LOCK_H
#define ASAN_LOCK_H
+#include "sanitizer_common/sanitizer_mutex.h"
#include "asan_internal.h"
// The locks in ASan are global objects and they are never destroyed to avoid
@@ -34,17 +35,7 @@
uptr owner_; // for debugging and for malloc_introspection_t interface
};
-class ScopedLock {
- public:
- explicit ScopedLock(AsanLock *mu) : mu_(mu) {
- mu_->Lock();
- }
- ~ScopedLock() {
- mu_->Unlock();
- }
- private:
- AsanLock *mu_;
-};
+typedef GenericScopedLock<AsanLock> ScopedLock;
} // namespace __asan
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h?rev=159438&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h Fri Jun 29 12:10:08 2012
@@ -0,0 +1,58 @@
+//===-- sanitizer_mutex.h ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SANITIZER_MUTEX_H
+#define SANITIZER_MUTEX_H
+
+#include "sanitizer_internal_defs.h"
+#include "sanitizer_atomic.h"
+
+namespace __sanitizer {
+
+template<typename MutexType>
+class GenericScopedLock {
+ public:
+ explicit GenericScopedLock(MutexType *mu)
+ : mu_(mu) {
+ mu_->Lock();
+ }
+
+ ~GenericScopedLock() {
+ mu_->Unlock();
+ }
+
+ private:
+ MutexType *mu_;
+
+ GenericScopedLock(const GenericScopedLock&);
+ void operator=(const GenericScopedLock&);
+};
+
+template<typename MutexType>
+class GenericScopedReadLock {
+ public:
+ explicit GenericScopedReadLock(MutexType *mu)
+ : mu_(mu) {
+ mu_->ReadLock();
+ }
+
+ ~GenericScopedReadLock() {
+ mu_->ReadUnlock();
+ }
+
+ private:
+ MutexType *mu_;
+
+ GenericScopedReadLock(const GenericScopedReadLock&);
+ void operator=(const GenericScopedReadLock&);
+};
+
+} // namespace __sanitizer
+
+#endif // SANITIZER_MUTEX_H
Propchange: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mutex.h
------------------------------------------------------------------------------
svn:eol-style = LF
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc?rev=159438&r1=159437&r2=159438&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc Fri Jun 29 12:10:08 2012
@@ -256,22 +256,4 @@
#endif
}
-Lock::Lock(Mutex *m)
- : m_(m) {
- m_->Lock();
-}
-
-Lock::~Lock() {
- m_->Unlock();
-}
-
-ReadLock::ReadLock(Mutex *m)
- : m_(m) {
- m_->ReadLock();
-}
-
-ReadLock::~ReadLock() {
- m_->ReadUnlock();
-}
-
} // namespace __tsan
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h?rev=159438&r1=159437&r2=159438&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h Fri Jun 29 12:10:08 2012
@@ -14,6 +14,7 @@
#define TSAN_MUTEX_H
#include "sanitizer_common/sanitizer_atomic.h"
+#include "sanitizer_common/sanitizer_mutex.h"
#include "tsan_defs.h"
namespace __tsan {
@@ -57,29 +58,8 @@
void operator = (const Mutex&);
};
-class Lock {
- public:
- explicit Lock(Mutex *m);
- ~Lock();
-
- private:
- Mutex *m_;
-
- Lock(const Lock&);
- void operator = (const Lock&);
-};
-
-class ReadLock {
- public:
- explicit ReadLock(Mutex *m);
- ~ReadLock();
-
- private:
- Mutex *m_;
-
- ReadLock(const ReadLock&);
- void operator = (const ReadLock&);
-};
+typedef GenericScopedLock<Mutex> Lock;
+typedef GenericScopedReadLock<Mutex> ReadLock;
class DeadlockDetector {
public:
More information about the llvm-commits
mailing list