1 // Copyright 2011 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "partition_alloc/partition_alloc_base/memory/ref_counted.h" 6 7 #include <limits> 8 #include <ostream> 9 #include <type_traits> 10 11 #include "build/build_config.h" 12 #include "partition_alloc/partition_alloc_base/debug/debugging_buildflags.h" 13 14 namespace partition_alloc::internal::base::subtle { 15 HasOneRef() const16bool RefCountedThreadSafeBase::HasOneRef() const { 17 return ref_count_.IsOne(); 18 } 19 HasAtLeastOneRef() const20bool RefCountedThreadSafeBase::HasAtLeastOneRef() const { 21 return !ref_count_.IsZero(); 22 } 23 24 #if BUILDFLAG(PA_DCHECK_IS_ON) ~RefCountedThreadSafeBase()25RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { 26 PA_BASE_DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without " 27 "calling Release()"; 28 } 29 #endif 30 31 // For security and correctness, we check the arithmetic on ref counts. 32 // 33 // In an attempt to avoid binary bloat (from inlining the `CHECK`), we define 34 // these functions out-of-line. However, compilers are wily. Further testing may 35 // show that `PA_NOINLINE` helps or hurts. 36 // 37 #if !defined(ARCH_CPU_X86_FAMILY) Release() const38bool RefCountedThreadSafeBase::Release() const { 39 return ReleaseImpl(); 40 } AddRef() const41void RefCountedThreadSafeBase::AddRef() const { 42 AddRefImpl(); 43 } AddRefWithCheck() const44void RefCountedThreadSafeBase::AddRefWithCheck() const { 45 AddRefWithCheckImpl(); 46 } 47 #endif 48 49 } // namespace partition_alloc::internal::base::subtle 50