Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
fml::internal::RefCountedThreadSafeBase Class Reference

#include <ref_counted_internal.h>

Inheritance diagram for fml::internal::RefCountedThreadSafeBase:
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< DirectManipulationEventHandler > fml::RefCountedThreadSafe< EngineLayer > fml::RefCountedThreadSafe< FlutterGpuTestClass > fml::RefCountedThreadSafe< FragmentProgram > fml::RefCountedThreadSafe< ImageDescriptor > fml::RefCountedThreadSafe< ImageFilter > fml::RefCountedThreadSafe< ImmutableBuffer > fml::RefCountedThreadSafe< NativeStringAttribute > fml::RefCountedThreadSafe< Paragraph > fml::RefCountedThreadSafe< ParagraphBuilder > fml::RefCountedThreadSafe< Picture > fml::RefCountedThreadSafe< PictureRecorder > fml::RefCountedThreadSafe< PlatformMessageResponse > fml::RefCountedThreadSafe< Scene > fml::RefCountedThreadSafe< SceneBuilder > fml::RefCountedThreadSafe< SceneNode > fml::RefCountedThreadSafe< SemanticsUpdate > fml::RefCountedThreadSafe< SemanticsUpdateBuilder > fml::RefCountedThreadSafe< Shader > fml::RefCountedThreadSafe< UnrefQueue< T > > fml::RefCountedThreadSafe< Vertices > fml::RefCountedThreadSafe< CommandBuffer > fml::RefCountedThreadSafe< Context > fml::RefCountedThreadSafe< DeviceBuffer > fml::RefCountedThreadSafe< HostBuffer > fml::RefCountedThreadSafe< RenderPass > fml::RefCountedThreadSafe< RenderPipeline > fml::RefCountedThreadSafe< ShaderLibrary > fml::RefCountedThreadSafe< Texture > fml::RefCountedThreadSafe< MyNativeClass > fml::RefCountedThreadSafe< TestVulkanContext > fml::RefCountedThreadSafe< MessageLoopImpl > fml::RefCountedThreadSafe< NativeLibrary > fml::RefCountedThreadSafe< RasterThreadMerger > fml::RefCountedThreadSafe< SharedThreadMerger > fml::RefCountedThreadSafe< TaskRunner > fml::RefCountedThreadSafe< WeakContainer > fml::RefCountedThreadSafe< Impl > fml::RefCountedThreadSafe< WeakPtrFlag > fml::RefCountedThreadSafe< VulkanProcTable > fml::RefCountedThreadSafe< Handle > fml::RefCountedThreadSafe< HandleDisposition > fml::RefCountedThreadSafe< HandleWaiter > fml::RefCountedThreadSafe< System > fml::RefCountedThreadSafe< T >

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.

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

◆ ~RefCountedThreadSafeBase()

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

Definition at line 95 of file ref_counted_internal.h.

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

Member Function Documentation

◆ AddRef()

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

Definition at line 21 of file ref_counted_internal.h.

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 }

◆ Adopt()

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

Definition at line 69 of file ref_counted_internal.h.

69 {
70 FML_DCHECK(adoption_required_);
71 adoption_required_ = false;
72 }

◆ AssertHasOneRef()

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

◆ HasOneRef()

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

Definition at line 29 of file ref_counted_internal.h.

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.

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 }

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