reentry_guard.cc 805 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 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/allocator/dispatcher/reentry_guard.h"
  5. #include "base/check.h"
  6. #include "base/compiler_specific.h"
  7. #include "build/build_config.h"
  8. #if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_ANDROID)
  9. #include <pthread.h>
  10. #endif
  11. namespace base::allocator::dispatcher {
  12. #if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_ANDROID)
  13. pthread_key_t ReentryGuard::entered_key_ = 0;
  14. void ReentryGuard::InitTLSSlot() {
  15. if (entered_key_ == 0) {
  16. int error = pthread_key_create(&entered_key_, nullptr);
  17. CHECK(!error);
  18. }
  19. DCHECK(entered_key_ != 0);
  20. }
  21. #else
  22. void ReentryGuard::InitTLSSlot() {}
  23. #endif
  24. } // namespace base::allocator::dispatcher