lock.cc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file is used for debugging assertion support. The Lock class
  5. // is functionally a wrapper around the LockImpl class, so the only
  6. // real intelligence in the class is in the debugging logic.
  7. #include "base/synchronization/lock.h"
  8. #if DCHECK_IS_ON()
  9. #include "base/threading/platform_thread.h"
  10. #endif
  11. #if DCHECK_IS_ON()
  12. namespace base {
  13. Lock::Lock() : lock_() {
  14. }
  15. Lock::~Lock() {
  16. DCHECK(owning_thread_ref_.is_null());
  17. }
  18. void Lock::AssertAcquired() const {
  19. DCHECK_EQ(owning_thread_ref_, PlatformThread::CurrentRef());
  20. }
  21. void Lock::CheckHeldAndUnmark() {
  22. DCHECK_EQ(owning_thread_ref_, PlatformThread::CurrentRef());
  23. owning_thread_ref_ = PlatformThreadRef();
  24. }
  25. void Lock::CheckUnheldAndMark() {
  26. DCHECK(owning_thread_ref_.is_null());
  27. owning_thread_ref_ = PlatformThread::CurrentRef();
  28. }
  29. } // namespace base
  30. #endif // DCHECK_IS_ON()