Flutter Engine
fml::internal::RefCountedThreadSafeBase Class Reference

#include <ref_counted_internal.h>

Inheritance diagram for fml::internal::RefCountedThreadSafeBase:
fml::RefCountedThreadSafe< T > fml::RefCountedThreadSafe< AndroidEnvironmentGL > fml::RefCountedThreadSafe< AndroidNativeWindow > fml::RefCountedThreadSafe< Canvas > fml::RefCountedThreadSafe< CanvasImage > fml::RefCountedThreadSafe< CanvasPath > fml::RefCountedThreadSafe< CanvasPathMeasure > fml::RefCountedThreadSafe< Codec > fml::RefCountedThreadSafe< ColorFilter > fml::RefCountedThreadSafe< DartSnapshot > fml::RefCountedThreadSafe< EngineLayer > fml::RefCountedThreadSafe< Handle > fml::RefCountedThreadSafe< HandleWaiter > fml::RefCountedThreadSafe< ImageDescriptor > fml::RefCountedThreadSafe< ImageFilter > fml::RefCountedThreadSafe< ImmutableBuffer > fml::RefCountedThreadSafe< Impl > fml::RefCountedThreadSafe< MessageLoopImpl > fml::RefCountedThreadSafe< MessageLoopTaskQueues > fml::RefCountedThreadSafe< NativeLibrary > fml::RefCountedThreadSafe< Paragraph > fml::RefCountedThreadSafe< ParagraphBuilder > fml::RefCountedThreadSafe< Picture > fml::RefCountedThreadSafe< PictureRecorder > fml::RefCountedThreadSafe< Pipeline< R > > fml::RefCountedThreadSafe< PlatformMessage > fml::RefCountedThreadSafe< PlatformMessageResponse > fml::RefCountedThreadSafe< RasterThreadMerger > fml::RefCountedThreadSafe< Scene > fml::RefCountedThreadSafe< SceneBuilder > fml::RefCountedThreadSafe< SceneHost > fml::RefCountedThreadSafe< SemanticsUpdate > fml::RefCountedThreadSafe< SemanticsUpdateBuilder > fml::RefCountedThreadSafe< Shader > fml::RefCountedThreadSafe< SkiaUnrefQueue > fml::RefCountedThreadSafe< System > fml::RefCountedThreadSafe< TaskRunner > fml::RefCountedThreadSafe< Vertices > fml::RefCountedThreadSafe< VulkanProcTable > fml::RefCountedThreadSafe< WeakPtrFlag >

Public Member Functions

void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Protected Member Functions

 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

Definition at line 19 of file ref_counted_internal.h.

Constructor & Destructor Documentation

◆ RefCountedThreadSafeBase()

fml::internal::RefCountedThreadSafeBase::RefCountedThreadSafeBase ( )
inlineprotected

Definition at line 86 of file ref_counted_internal.h.

Referenced by AssertHasOneRef().

87  : ref_count_(1u)
88 #ifndef NDEBUG
89  ,
90  adoption_required_(true),
91  destruction_started_(false)
92 #endif
93 {
94 }

◆ ~RefCountedThreadSafeBase()

fml::internal::RefCountedThreadSafeBase::~RefCountedThreadSafeBase ( )
inlineprotected

Definition at line 96 of file ref_counted_internal.h.

References FML_DCHECK.

Referenced by AssertHasOneRef().

96  {
97 #ifndef NDEBUG
98  FML_DCHECK(!adoption_required_);
99  // Should only be destroyed as a result of |Release()|.
100  FML_DCHECK(destruction_started_);
101 #endif
102 }
#define FML_DCHECK(condition)
Definition: logging.h:86

Member Function Documentation

◆ AddRef()

void fml::internal::RefCountedThreadSafeBase::AddRef ( ) const
inline

Definition at line 21 of file ref_counted_internal.h.

References FML_DCHECK.

Referenced by zircon::dart::Handle::koid(), and flutter::RefCountedDartWrappable< ColorFilter >::RetainDartWrappableReference().

21  {
22 #ifndef NDEBUG
23  FML_DCHECK(!adoption_required_);
24  FML_DCHECK(!destruction_started_);
25 #endif
26  ref_count_.fetch_add(1u, std::memory_order_relaxed);
27  }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ Adopt()

void fml::internal::RefCountedThreadSafeBase::Adopt ( )
inlineprotected

Definition at line 69 of file ref_counted_internal.h.

References FML_DCHECK.

Referenced by fml::RefCountedThreadSafe< ColorFilter >::~RefCountedThreadSafe().

69  {
70  FML_DCHECK(adoption_required_);
71  adoption_required_ = false;
72  }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ AssertHasOneRef()

void fml::internal::RefCountedThreadSafeBase::AssertHasOneRef ( ) const
inline

Definition at line 33 of file ref_counted_internal.h.

References FML_DCHECK, HasOneRef(), RefCountedThreadSafeBase(), and ~RefCountedThreadSafeBase().

33 { FML_DCHECK(HasOneRef()); }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ HasOneRef()

bool fml::internal::RefCountedThreadSafeBase::HasOneRef ( ) const
inline

Definition at line 29 of file ref_counted_internal.h.

Referenced by AssertHasOneRef().

29  {
30  return ref_count_.load(std::memory_order_acquire) == 1u;
31  }

◆ Release()

bool fml::internal::RefCountedThreadSafeBase::Release ( ) const
inlineprotected

Definition at line 40 of file ref_counted_internal.h.

References FML_DCHECK.

Referenced by fml::RefCountedThreadSafe< ColorFilter >::Release().

40  {
41 #ifndef NDEBUG
42  FML_DCHECK(!adoption_required_);
43  FML_DCHECK(!destruction_started_);
44 #endif
45  FML_DCHECK(ref_count_.load(std::memory_order_acquire) != 0u);
46  // TODO(vtl): We could add the following:
47  // if (ref_count_.load(std::memory_order_relaxed) == 1u) {
48  // #ifndef NDEBUG
49  // destruction_started_= true;
50  // #endif
51  // return true;
52  // }
53  // This would be correct. On ARM (an Nexus 4), in *single-threaded* tests,
54  // this seems to make the destruction case marginally faster (barely
55  // measurable), and while the non-destruction case remains about the same
56  // (possibly marginally slower, but my measurements aren't good enough to
57  // have any confidence in that). I should try multithreaded/multicore tests.
58  if (ref_count_.fetch_sub(1u, std::memory_order_release) == 1u) {
59  std::atomic_thread_fence(std::memory_order_acquire);
60 #ifndef NDEBUG
61  destruction_started_ = true;
62 #endif
63  return true;
64  }
65  return false;
66  }
#define FML_DCHECK(condition)
Definition: logging.h:86

The documentation for this class was generated from the following file: