asan_lock.h revision c04d8b39795b8faab2c172da59462f4e54823533
1//===-- asan_lock.h ---------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of AddressSanitizer, an address sanity checker. 11// 12// A wrapper for a simple lock. 13//===----------------------------------------------------------------------===// 14#ifndef ASAN_LOCK_H 15#define ASAN_LOCK_H 16 17#include "sanitizer_common/sanitizer_mutex.h" 18#include "asan_internal.h" 19 20// The locks in ASan are global objects and they are never destroyed to avoid 21// at-exit races (that is, a lock is being used by other threads while the main 22// thread is doing atexit destructors). 23// We define the class using opaque storage to avoid including system headers. 24 25namespace __asan { 26 27class AsanLock { 28 public: 29 explicit AsanLock(LinkerInitialized); 30 void Lock(); 31 void Unlock(); 32 bool IsLocked() { return owner_ != 0; } 33 private: 34 uptr opaque_storage_[10]; 35 uptr owner_; // for debugging and for malloc_introspection_t interface 36}; 37 38typedef GenericScopedLock<AsanLock> ScopedLock; 39 40} // namespace __asan 41 42#endif // ASAN_LOCK_H 43