Flutter Engine
The Flutter Engine
shared_thread_merger.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FML_SHARED_THREAD_MERGER_H_
6#define FLUTTER_FML_SHARED_THREAD_MERGER_H_
7
8#include <condition_variable>
9#include <mutex>
10
11#include "flutter/fml/macros.h"
12#include "flutter/fml/memory/ref_counted.h"
13#include "flutter/fml/message_loop_task_queues.h"
14
15namespace fml {
16
17class RasterThreadMerger;
18
20
21/// Instance of this class is shared between multiple |RasterThreadMerger|
22/// instances, Most of the callings from |RasterThreadMerger| will be redirected
23/// to this class with one more caller parameter.
25 : public fml::RefCountedThreadSafe<SharedThreadMerger> {
26 public:
28
29 // It's called by |RasterThreadMerger::MergeWithLease|.
30 // See the doc of |RasterThreadMerger::MergeWithLease|.
31 bool MergeWithLease(RasterThreadMergerId caller, size_t lease_term);
32
33 // It's called by |RasterThreadMerger::UnMergeNowIfLastOne|.
34 // See the doc of |RasterThreadMerger::UnMergeNowIfLastOne|.
36
37 // It's called by |RasterThreadMerger::ExtendLeaseTo|.
38 // See the doc of |RasterThreadMerger::ExtendLeaseTo|.
39 void ExtendLeaseTo(RasterThreadMergerId caller, size_t lease_term);
40
41 // It's called by |RasterThreadMerger::IsMergedUnSafe|.
42 // See the doc of |RasterThreadMerger::IsMergedUnSafe|.
43 bool IsMergedUnSafe() const;
44
45 // It's called by |RasterThreadMerger::IsEnabledUnSafe|.
46 // See the doc of |RasterThreadMerger::IsEnabledUnSafe|.
47 bool IsEnabledUnSafe() const;
48
49 // It's called by |RasterThreadMerger::Enable| or
50 // |RasterThreadMerger::Disable|.
51 void SetEnabledUnSafe(bool enabled);
52
53 // It's called by |RasterThreadMerger::DecrementLease|.
54 // See the doc of |RasterThreadMerger::DecrementLease|.
56
57 private:
58 fml::TaskQueueId owner_;
59 fml::TaskQueueId subsumed_;
60 fml::MessageLoopTaskQueues* task_queues_;
61 std::mutex mutex_;
62 bool enabled_ = false;
63
64 /// The |MergeWithLease| or |ExtendLeaseTo| method will record the caller
65 /// into this lease_term_by_caller_ map, |UnMergeNowIfLastOne|
66 /// method will remove the caller from this lease_term_by_caller_.
67 std::map<RasterThreadMergerId, std::atomic_size_t> lease_term_by_caller_;
68
69 bool IsAllLeaseTermsZeroUnSafe() const;
70
71 bool UnMergeNowUnSafe();
72
73 FML_DISALLOW_COPY_AND_ASSIGN(SharedThreadMerger);
74};
75
76} // namespace fml
77
78#endif // FLUTTER_FML_SHARED_THREAD_MERGER_H_
SharedThreadMerger(TaskQueueId owner, TaskQueueId subsumed)
bool UnMergeNowIfLastOne(RasterThreadMergerId caller)
void SetEnabledUnSafe(bool enabled)
void ExtendLeaseTo(RasterThreadMergerId caller, size_t lease_term)
bool DecrementLease(RasterThreadMergerId caller)
bool MergeWithLease(RasterThreadMergerId caller, size_t lease_term)
Definition: ascii_trie.cc:9
void * RasterThreadMergerId