• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "partition_alloc/partition_alloc_base/debug/debugging_buildflags.h"
12 
13 namespace partition_alloc::internal::base::subtle {
14 
HasOneRef() const15 bool RefCountedThreadSafeBase::HasOneRef() const {
16   return ref_count_.IsOne();
17 }
18 
HasAtLeastOneRef() const19 bool RefCountedThreadSafeBase::HasAtLeastOneRef() const {
20   return !ref_count_.IsZero();
21 }
22 
23 #if BUILDFLAG(PA_DCHECK_IS_ON)
~RefCountedThreadSafeBase()24 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
25   PA_BASE_DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
26                               "calling Release()";
27 }
28 #endif
29 
30 // For security and correctness, we check the arithmetic on ref counts.
31 //
32 // In an attempt to avoid binary bloat (from inlining the `CHECK`), we define
33 // these functions out-of-line. However, compilers are wily. Further testing may
34 // show that `PA_NOINLINE` helps or hurts.
35 //
36 #if !defined(ARCH_CPU_X86_FAMILY)
Release() const37 bool RefCountedThreadSafeBase::Release() const {
38   return ReleaseImpl();
39 }
AddRef() const40 void RefCountedThreadSafeBase::AddRef() const {
41   AddRefImpl();
42 }
AddRefWithCheck() const43 void RefCountedThreadSafeBase::AddRefWithCheck() const {
44   AddRefWithCheckImpl();
45 }
46 #endif
47 
48 }  // namespace partition_alloc::internal::base::subtle
49