5#define FML_USED_ON_EMBEDDER
7#include "flutter/fml/shared_thread_merger.h"
23 FML_DCHECK(lease_term > 0) <<
"lease_term should be positive.";
24 std::scoped_lock lock(mutex_);
28 bool success = task_queues_->
Merge(owner_, subsumed_);
29 FML_CHECK(success) <<
"Unable to merge the raster and platform threads.";
31 lease_term_by_caller_[caller] = lease_term;
35bool SharedThreadMerger::UnMergeNowUnSafe() {
37 <<
"all lease term records must be zero before calling "
39 bool success = task_queues_->
Unmerge(owner_, subsumed_);
40 FML_CHECK(success) <<
"Unable to un-merge the raster and platform threads.";
45 std::scoped_lock lock(mutex_);
46 lease_term_by_caller_.erase(caller);
47 if (lease_term_by_caller_.empty() || IsAllLeaseTermsZeroUnSafe()) {
48 return UnMergeNowUnSafe();
54 std::scoped_lock lock(mutex_);
55 auto entry = lease_term_by_caller_.find(caller);
56 bool exist = entry != lease_term_by_caller_.end();
58 std::atomic_size_t& lease_term_ref = entry->second;
60 <<
"lease_term should always be positive when merged, lease_term="
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="
69 if (IsAllLeaseTermsZeroUnSafe()) {
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;
87 return !IsAllLeaseTermsZeroUnSafe();
98bool SharedThreadMerger::IsAllLeaseTermsZeroUnSafe()
const {
99 return std::all_of(lease_term_by_caller_.begin(), lease_term_by_caller_.end(),
100 [&](
const auto& item) { return item.second == 0; });
bool Merge(TaskQueueId owner, TaskQueueId subsumed)
bool Unmerge(TaskQueueId owner, TaskQueueId subsumed)
SharedThreadMerger(TaskQueueId owner, TaskQueueId subsumed)
bool UnMergeNowIfLastOne(RasterThreadMergerId caller)
bool IsMergedUnSafe() const
void SetEnabledUnSafe(bool enabled)
bool IsEnabledUnSafe() const
void ExtendLeaseTo(RasterThreadMergerId caller, size_t lease_term)
bool DecrementLease(RasterThreadMergerId caller)
bool MergeWithLease(RasterThreadMergerId caller, size_t lease_term)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
void * RasterThreadMergerId