thread_checker.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2022 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. #include "base/threading/thread_checker.h"
  5. #if DCHECK_IS_ON()
  6. #include <memory>
  7. #include <ostream>
  8. #include "base/check.h"
  9. #include "base/debug/stack_trace.h"
  10. #endif
  11. namespace base {
  12. #if DCHECK_IS_ON()
  13. ScopedValidateThreadChecker::ScopedValidateThreadChecker(
  14. const ThreadChecker& checker) {
  15. std::unique_ptr<debug::StackTrace> bound_at;
  16. DCHECK(checker.CalledOnValidThread(&bound_at))
  17. << (bound_at ? "\nWas attached to thread at:\n" + bound_at->ToString()
  18. : "");
  19. }
  20. ScopedValidateThreadChecker::ScopedValidateThreadChecker(
  21. const ThreadChecker& checker,
  22. const StringPiece& msg) {
  23. std::unique_ptr<debug::StackTrace> bound_at;
  24. DCHECK(checker.CalledOnValidThread(&bound_at))
  25. << msg
  26. << (bound_at ? "\nWas attached to thread at:\n" + bound_at->ToString()
  27. : "");
  28. }
  29. ScopedValidateThreadChecker::~ScopedValidateThreadChecker() = default;
  30. #endif // DCHECK_IS_ON()
  31. } // namespace base