Skip to content

Commit

Permalink
tsan: rename test Mutex to UserMutex
Browse files Browse the repository at this point in the history
Rename Mutex class in tests to avoid conflicts with sanitizer_common Mutex.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D106547
  • Loading branch information
dvyukov committed Jul 23, 2021
1 parent 0224399 commit cfed8d0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/tests/rtl/tsan_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST(DISABLED_BENCH, FuncCall) {
}

TEST(DISABLED_BENCH, MutexLocal) {
Mutex m;
UserMutex m;
ScopedThread().Create(m);
for (int i = 0; i < 50; i++) {
ScopedThread t;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/tsan/tests/rtl/tsan_mop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(ThreadSanitizer, WriteThenRead) {
}

TEST(ThreadSanitizer, WriteThenLockedRead) {
Mutex m(Mutex::RW);
UserMutex m(UserMutex::RW);
MainThread t0;
t0.Create(m);
MemLoc l;
Expand All @@ -84,7 +84,7 @@ TEST(ThreadSanitizer, WriteThenLockedRead) {
}

TEST(ThreadSanitizer, LockedWriteThenRead) {
Mutex m(Mutex::RW);
UserMutex m(UserMutex::RW);
MainThread t0;
t0.Create(m);
MemLoc l;
Expand Down
14 changes: 7 additions & 7 deletions compiler-rt/lib/tsan/tests/rtl/tsan_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace __tsan {

TEST(ThreadSanitizer, BasicMutex) {
ScopedThread t;
Mutex m;
UserMutex m;
t.Create(m);

t.Lock(m);
Expand All @@ -38,7 +38,7 @@ TEST(ThreadSanitizer, BasicMutex) {

TEST(ThreadSanitizer, BasicSpinMutex) {
ScopedThread t;
Mutex m(Mutex::Spin);
UserMutex m(UserMutex::Spin);
t.Create(m);

t.Lock(m);
Expand All @@ -56,7 +56,7 @@ TEST(ThreadSanitizer, BasicSpinMutex) {

TEST(ThreadSanitizer, BasicRwMutex) {
ScopedThread t;
Mutex m(Mutex::RW);
UserMutex m(UserMutex::RW);
t.Create(m);

t.Lock(m);
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST(ThreadSanitizer, BasicRwMutex) {
}

TEST(ThreadSanitizer, Mutex) {
Mutex m;
UserMutex m;
MainThread t0;
t0.Create(m);

Expand All @@ -108,7 +108,7 @@ TEST(ThreadSanitizer, Mutex) {
}

TEST(ThreadSanitizer, SpinMutex) {
Mutex m(Mutex::Spin);
UserMutex m(UserMutex::Spin);
MainThread t0;
t0.Create(m);

Expand All @@ -124,7 +124,7 @@ TEST(ThreadSanitizer, SpinMutex) {
}

TEST(ThreadSanitizer, RwMutex) {
Mutex m(Mutex::RW);
UserMutex m(UserMutex::RW);
MainThread t0;
t0.Create(m);

Expand All @@ -150,7 +150,7 @@ TEST(ThreadSanitizer, RwMutex) {

TEST(ThreadSanitizer, StaticMutex) {
// Emulates statically initialized mutex.
Mutex m;
UserMutex m;
m.StaticInit();
{
ScopedThread t1, t2;
Expand Down
26 changes: 13 additions & 13 deletions compiler-rt/lib/tsan/tests/rtl/tsan_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MemLoc {
void operator = (const MemLoc&);
};

class Mutex {
class UserMutex {
public:
enum Type {
Normal,
Expand All @@ -40,8 +40,8 @@ class Mutex {
#endif
};

explicit Mutex(Type type = Normal);
~Mutex();
explicit UserMutex(Type type = Normal);
~UserMutex();

void Init();
void StaticInit(); // Emulates static initialization (tsan invisible).
Expand All @@ -59,8 +59,8 @@ class Mutex {
bool alive_;
const Type type_;

Mutex(const Mutex&);
void operator = (const Mutex&);
UserMutex(const UserMutex &);
void operator=(const UserMutex &);
};

// A thread is started in CTOR and joined in DTOR.
Expand Down Expand Up @@ -100,14 +100,14 @@ class ScopedThread {
void Call(void(*pc)());
void Return();

void Create(const Mutex &m);
void Destroy(const Mutex &m);
void Lock(const Mutex &m);
bool TryLock(const Mutex &m);
void Unlock(const Mutex &m);
void ReadLock(const Mutex &m);
bool TryReadLock(const Mutex &m);
void ReadUnlock(const Mutex &m);
void Create(const UserMutex &m);
void Destroy(const UserMutex &m);
void Lock(const UserMutex &m);
bool TryLock(const UserMutex &m);
void Unlock(const UserMutex &m);
void ReadLock(const UserMutex &m);
bool TryReadLock(const UserMutex &m);
void ReadUnlock(const UserMutex &m);

void Memcpy(void *dst, const void *src, int size, bool expect_race = false);
void Memset(void *dst, int val, int size, bool expect_race = false);
Expand Down
59 changes: 27 additions & 32 deletions compiler-rt/lib/tsan/tests/rtl/tsan_test_util_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,11 @@ MemLoc::MemLoc(int offset_from_aligned)
MemLoc::~MemLoc() {
}

Mutex::Mutex(Type type)
: alive_()
, type_(type) {
}
UserMutex::UserMutex(Type type) : alive_(), type_(type) {}

Mutex::~Mutex() {
CHECK(!alive_);
}
UserMutex::~UserMutex() { CHECK(!alive_); }

void Mutex::Init() {
void UserMutex::Init() {
CHECK(!alive_);
alive_ = true;
if (type_ == Normal)
Expand All @@ -114,15 +109,15 @@ void Mutex::Init() {
CHECK(0);
}

void Mutex::StaticInit() {
void UserMutex::StaticInit() {
CHECK(!alive_);
CHECK(type_ == Normal);
alive_ = true;
pthread_mutex_t tmp = PTHREAD_MUTEX_INITIALIZER;
memcpy(mtx_, &tmp, sizeof(tmp));
}

void Mutex::Destroy() {
void UserMutex::Destroy() {
CHECK(alive_);
alive_ = false;
if (type_ == Normal)
Expand All @@ -135,7 +130,7 @@ void Mutex::Destroy() {
CHECK_EQ(__interceptor_pthread_rwlock_destroy((pthread_rwlock_t*)mtx_), 0);
}

void Mutex::Lock() {
void UserMutex::Lock() {
CHECK(alive_);
if (type_ == Normal)
CHECK_EQ(__interceptor_pthread_mutex_lock((pthread_mutex_t*)mtx_), 0);
Expand All @@ -147,7 +142,7 @@ void Mutex::Lock() {
CHECK_EQ(__interceptor_pthread_rwlock_wrlock((pthread_rwlock_t*)mtx_), 0);
}

bool Mutex::TryLock() {
bool UserMutex::TryLock() {
CHECK(alive_);
if (type_ == Normal)
return __interceptor_pthread_mutex_trylock((pthread_mutex_t*)mtx_) == 0;
Expand All @@ -160,7 +155,7 @@ bool Mutex::TryLock() {
return false;
}

void Mutex::Unlock() {
void UserMutex::Unlock() {
CHECK(alive_);
if (type_ == Normal)
CHECK_EQ(__interceptor_pthread_mutex_unlock((pthread_mutex_t*)mtx_), 0);
Expand All @@ -172,19 +167,19 @@ void Mutex::Unlock() {
CHECK_EQ(__interceptor_pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
}

void Mutex::ReadLock() {
void UserMutex::ReadLock() {
CHECK(alive_);
CHECK(type_ == RW);
CHECK_EQ(__interceptor_pthread_rwlock_rdlock((pthread_rwlock_t*)mtx_), 0);
}

bool Mutex::TryReadLock() {
bool UserMutex::TryReadLock() {
CHECK(alive_);
CHECK(type_ == RW);
return __interceptor_pthread_rwlock_tryrdlock((pthread_rwlock_t*)mtx_) == 0;
}

void Mutex::ReadUnlock() {
void UserMutex::ReadUnlock() {
CHECK(alive_);
CHECK(type_ == RW);
CHECK_EQ(__interceptor_pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
Expand Down Expand Up @@ -310,28 +305,28 @@ void ScopedThread::Impl::HandleEvent(Event *ev) {
__tsan_func_exit();
break;
case Event::MUTEX_CREATE:
static_cast<Mutex*>(ev->ptr)->Init();
static_cast<UserMutex *>(ev->ptr)->Init();
break;
case Event::MUTEX_DESTROY:
static_cast<Mutex*>(ev->ptr)->Destroy();
static_cast<UserMutex *>(ev->ptr)->Destroy();
break;
case Event::MUTEX_LOCK:
static_cast<Mutex*>(ev->ptr)->Lock();
static_cast<UserMutex *>(ev->ptr)->Lock();
break;
case Event::MUTEX_TRYLOCK:
ev->res = static_cast<Mutex*>(ev->ptr)->TryLock();
ev->res = static_cast<UserMutex *>(ev->ptr)->TryLock();
break;
case Event::MUTEX_UNLOCK:
static_cast<Mutex*>(ev->ptr)->Unlock();
static_cast<UserMutex *>(ev->ptr)->Unlock();
break;
case Event::MUTEX_READLOCK:
static_cast<Mutex*>(ev->ptr)->ReadLock();
static_cast<UserMutex *>(ev->ptr)->ReadLock();
break;
case Event::MUTEX_TRYREADLOCK:
ev->res = static_cast<Mutex*>(ev->ptr)->TryReadLock();
ev->res = static_cast<UserMutex *>(ev->ptr)->TryReadLock();
break;
case Event::MUTEX_READUNLOCK:
static_cast<Mutex*>(ev->ptr)->ReadUnlock();
static_cast<UserMutex *>(ev->ptr)->ReadUnlock();
break;
case Event::MEMCPY:
__interceptor_memcpy(ev->ptr, (void*)ev->arg, ev->arg2);
Expand Down Expand Up @@ -440,44 +435,44 @@ void ScopedThread::Return() {
impl_->send(&event);
}

void ScopedThread::Create(const Mutex &m) {
void ScopedThread::Create(const UserMutex &m) {
Event event(Event::MUTEX_CREATE, &m);
impl_->send(&event);
}

void ScopedThread::Destroy(const Mutex &m) {
void ScopedThread::Destroy(const UserMutex &m) {
Event event(Event::MUTEX_DESTROY, &m);
impl_->send(&event);
}

void ScopedThread::Lock(const Mutex &m) {
void ScopedThread::Lock(const UserMutex &m) {
Event event(Event::MUTEX_LOCK, &m);
impl_->send(&event);
}

bool ScopedThread::TryLock(const Mutex &m) {
bool ScopedThread::TryLock(const UserMutex &m) {
Event event(Event::MUTEX_TRYLOCK, &m);
impl_->send(&event);
return event.res;
}

void ScopedThread::Unlock(const Mutex &m) {
void ScopedThread::Unlock(const UserMutex &m) {
Event event(Event::MUTEX_UNLOCK, &m);
impl_->send(&event);
}

void ScopedThread::ReadLock(const Mutex &m) {
void ScopedThread::ReadLock(const UserMutex &m) {
Event event(Event::MUTEX_READLOCK, &m);
impl_->send(&event);
}

bool ScopedThread::TryReadLock(const Mutex &m) {
bool ScopedThread::TryReadLock(const UserMutex &m) {
Event event(Event::MUTEX_TRYREADLOCK, &m);
impl_->send(&event);
return event.res;
}

void ScopedThread::ReadUnlock(const Mutex &m) {
void ScopedThread::ReadUnlock(const UserMutex &m) {
Event event(Event::MUTEX_READUNLOCK, &m);
impl_->send(&event);
}
Expand Down

0 comments on commit cfed8d0

Please sign in to comment.