2012-05-10 21:48:04 +08:00
|
|
|
//===-- tsan_mutex.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef TSAN_MUTEX_H
|
|
|
|
#define TSAN_MUTEX_H
|
|
|
|
|
2012-06-30 00:58:33 +08:00
|
|
|
#include "sanitizer_common/sanitizer_atomic.h"
|
2012-06-30 01:10:08 +08:00
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_defs.h"
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
|
|
|
enum MutexType {
|
|
|
|
MutexTypeInvalid,
|
|
|
|
MutexTypeTrace,
|
|
|
|
MutexTypeThreads,
|
|
|
|
MutexTypeReport,
|
|
|
|
MutexTypeSyncVar,
|
|
|
|
MutexTypeSyncTab,
|
|
|
|
MutexTypeSlab,
|
|
|
|
MutexTypeAnnotations,
|
|
|
|
MutexTypeAtExit,
|
2012-12-06 20:16:15 +08:00
|
|
|
MutexTypeMBlock,
|
2012-12-21 01:29:34 +08:00
|
|
|
MutexTypeJava,
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// This must be the last.
|
2012-09-13 19:54:41 +08:00
|
|
|
MutexTypeCount
|
2012-05-10 21:48:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Mutex {
|
|
|
|
public:
|
|
|
|
explicit Mutex(MutexType type, StatType stat_type);
|
|
|
|
~Mutex();
|
|
|
|
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
void ReadLock();
|
|
|
|
void ReadUnlock();
|
|
|
|
|
2012-08-30 21:02:30 +08:00
|
|
|
void CheckLocked();
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
private:
|
|
|
|
atomic_uintptr_t state_;
|
|
|
|
#if TSAN_DEBUG
|
|
|
|
MutexType type_;
|
|
|
|
#endif
|
|
|
|
#if TSAN_COLLECT_STATS
|
|
|
|
StatType stat_type_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Mutex(const Mutex&);
|
|
|
|
void operator = (const Mutex&);
|
|
|
|
};
|
|
|
|
|
2012-06-30 01:10:08 +08:00
|
|
|
typedef GenericScopedLock<Mutex> Lock;
|
|
|
|
typedef GenericScopedReadLock<Mutex> ReadLock;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
class DeadlockDetector {
|
|
|
|
public:
|
|
|
|
DeadlockDetector();
|
|
|
|
void Lock(MutexType t);
|
|
|
|
void Unlock(MutexType t);
|
|
|
|
private:
|
|
|
|
u64 seq_;
|
|
|
|
u64 locked_[MutexTypeCount];
|
|
|
|
};
|
|
|
|
|
|
|
|
void InitializeMutex();
|
|
|
|
|
|
|
|
} // namespace __tsan
|
|
|
|
|
|
|
|
#endif // TSAN_MUTEX_H
|