Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
fml::SharedThreadMerger Class Reference

#include <shared_thread_merger.h>

Inheritance diagram for fml::SharedThreadMerger:
fml::RefCountedThreadSafe< SharedThreadMerger > fml::internal::RefCountedThreadSafeBase

Public Member Functions

 SharedThreadMerger (TaskQueueId owner, TaskQueueId subsumed)
 
bool MergeWithLease (RasterThreadMergerId caller, size_t lease_term)
 
bool UnMergeNowIfLastOne (RasterThreadMergerId caller)
 
void ExtendLeaseTo (RasterThreadMergerId caller, size_t lease_term)
 
bool IsMergedUnSafe () const
 
bool IsEnabledUnSafe () const
 
void SetEnabledUnSafe (bool enabled)
 
bool DecrementLease (RasterThreadMergerId caller)
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< SharedThreadMerger >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Additional Inherited Members

- Protected Member Functions inherited from fml::RefCountedThreadSafe< SharedThreadMerger >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

Instance of this class is shared between multiple |RasterThreadMerger| instances, Most of the callings from |RasterThreadMerger| will be redirected to this class with one more caller parameter.

Definition at line 24 of file shared_thread_merger.h.

Constructor & Destructor Documentation

◆ SharedThreadMerger()

fml::SharedThreadMerger::SharedThreadMerger ( fml::TaskQueueId  owner,
fml::TaskQueueId  subsumed 
)

Definition at line 14 of file shared_thread_merger.cc.

16 : owner_(owner),
17 subsumed_(subsumed),
19 enabled_(true) {}
static MessageLoopTaskQueues * GetInstance()

Member Function Documentation

◆ DecrementLease()

bool fml::SharedThreadMerger::DecrementLease ( RasterThreadMergerId  caller)

Definition at line 53 of file shared_thread_merger.cc.

53 {
54 std::scoped_lock lock(mutex_);
55 auto entry = lease_term_by_caller_.find(caller);
56 bool exist = entry != lease_term_by_caller_.end();
57 if (exist) {
58 std::atomic_size_t& lease_term_ref = entry->second;
59 FML_CHECK(lease_term_ref > 0)
60 << "lease_term should always be positive when merged, lease_term="
61 << lease_term_ref;
62 lease_term_ref--;
63 } else {
64 FML_LOG(WARNING) << "The caller does not exist when calling "
65 "DecrementLease(), ignored. This may happens after "
66 "caller is erased in UnMergeNowIfLastOne(). caller="
67 << caller;
68 }
69 if (IsAllLeaseTermsZeroUnSafe()) {
70 // Unmerge now because lease_term_ decreased to zero.
71 UnMergeNowUnSafe();
72 return true;
73 }
74 return false;
75}
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_CHECK(condition)
Definition: logging.h:85

◆ ExtendLeaseTo()

void fml::SharedThreadMerger::ExtendLeaseTo ( RasterThreadMergerId  caller,
size_t  lease_term 
)

Definition at line 77 of file shared_thread_merger.cc.

78 {
79 FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
80 std::scoped_lock lock(mutex_);
82 << "should be merged state when calling this method";
83 lease_term_by_caller_[caller] = lease_term;
84}
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ IsEnabledUnSafe()

bool fml::SharedThreadMerger::IsEnabledUnSafe ( ) const

Definition at line 90 of file shared_thread_merger.cc.

90 {
91 return enabled_;
92}

◆ IsMergedUnSafe()

bool fml::SharedThreadMerger::IsMergedUnSafe ( ) const

Definition at line 86 of file shared_thread_merger.cc.

86 {
87 return !IsAllLeaseTermsZeroUnSafe();
88}

◆ MergeWithLease()

bool fml::SharedThreadMerger::MergeWithLease ( RasterThreadMergerId  caller,
size_t  lease_term 
)

Definition at line 21 of file shared_thread_merger.cc.

22 {
23 FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
24 std::scoped_lock lock(mutex_);
25 if (IsMergedUnSafe()) {
26 return true;
27 }
28 bool success = task_queues_->Merge(owner_, subsumed_);
29 FML_CHECK(success) << "Unable to merge the raster and platform threads.";
30 // Save the lease term
31 lease_term_by_caller_[caller] = lease_term;
32 return success;
33}
bool Merge(TaskQueueId owner, TaskQueueId subsumed)

◆ SetEnabledUnSafe()

void fml::SharedThreadMerger::SetEnabledUnSafe ( bool  enabled)

Definition at line 94 of file shared_thread_merger.cc.

94 {
95 enabled_ = enabled;
96}

◆ UnMergeNowIfLastOne()

bool fml::SharedThreadMerger::UnMergeNowIfLastOne ( RasterThreadMergerId  caller)

Definition at line 44 of file shared_thread_merger.cc.

44 {
45 std::scoped_lock lock(mutex_);
46 lease_term_by_caller_.erase(caller);
47 if (lease_term_by_caller_.empty() || IsAllLeaseTermsZeroUnSafe()) {
48 return UnMergeNowUnSafe();
49 }
50 return true;
51}

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