Flutter Engine
flutter::Pipeline< R > Class Template Reference

#include <pipeline.h>

Inheritance diagram for flutter::Pipeline< R >:
fml::RefCountedThreadSafe< Pipeline< R > > fml::internal::RefCountedThreadSafeBase

Classes

class  ProducerContinuation
 

Public Types

using Resource = R
 
using ResourcePtr = std::unique_ptr< Resource >
 
using Consumer = std::function< void(ResourcePtr)>
 

Public Member Functions

 Pipeline (uint32_t depth)
 
 ~Pipeline ()=default
 
bool IsValid () const
 
ProducerContinuation Produce ()
 
ProducerContinuation ProduceIfEmpty ()
 
PipelineConsumeResult Consume (const Consumer &consumer)
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Pipeline< R > >
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< Pipeline< R > >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

template<class R>
class flutter::Pipeline< R >

A thread-safe queue of resources for a single consumer and a single producer.

Definition at line 30 of file pipeline.h.

Member Typedef Documentation

◆ Consumer

template<class R>
using flutter::Pipeline< R >::Consumer = std::function<void(ResourcePtr)>

Definition at line 136 of file pipeline.h.

◆ Resource

template<class R>
using flutter::Pipeline< R >::Resource = R

Definition at line 32 of file pipeline.h.

◆ ResourcePtr

template<class R>
using flutter::Pipeline< R >::ResourcePtr = std::unique_ptr<Resource>

Definition at line 33 of file pipeline.h.

Constructor & Destructor Documentation

◆ Pipeline()

template<class R>
flutter::Pipeline< R >::Pipeline ( uint32_t  depth)
inlineexplicit

Definition at line 93 of file pipeline.h.

94  : depth_(depth), empty_(depth), available_(0), inflight_(0) {}

◆ ~Pipeline()

template<class R>
flutter::Pipeline< R >::~Pipeline ( )
default

Member Function Documentation

◆ Consume()

template<class R>
PipelineConsumeResult flutter::Pipeline< R >::Consume ( const Consumer consumer)
inline
Note
Procedure doesn't copy all closures.

Definition at line 139 of file pipeline.h.

References flutter::Done, FML_DISALLOW_COPY_AND_ASSIGN, flutter::MoreAvailable, flutter::NoneAvailable, fml::Semaphore::Signal(), TRACE_EVENT0, TRACE_EVENT_ASYNC_END0, and TRACE_FLOW_END.

Referenced by flutter::testing::TEST().

139  {
140  if (consumer == nullptr) {
142  }
143 
144  if (!available_.TryWait()) {
146  }
147 
148  ResourcePtr resource;
149  size_t trace_id = 0;
150  size_t items_count = 0;
151 
152  {
153  std::scoped_lock lock(queue_mutex_);
154  std::tie(resource, trace_id) = std::move(queue_.front());
155  queue_.pop_front();
156  items_count = queue_.size();
157  }
158 
159  {
160  TRACE_EVENT0("flutter", "PipelineConsume");
161  consumer(std::move(resource));
162  }
163 
164  empty_.Signal();
165  --inflight_;
166 
167  TRACE_FLOW_END("flutter", "PipelineItem", trace_id);
168  TRACE_EVENT_ASYNC_END0("flutter", "PipelineItem", trace_id);
169 
170  return items_count > 0 ? PipelineConsumeResult::MoreAvailable
172  }
std::unique_ptr< Resource > ResourcePtr
Definition: pipeline.h:33
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define TRACE_FLOW_END(category, name, id)
Definition: trace_event.h:121
#define TRACE_EVENT_ASYNC_END0(category_group, name, id)
Definition: trace_event.h:92
bool TryWait()
Definition: semaphore.cc:157

◆ IsValid()

template<class R>
bool flutter::Pipeline< R >::IsValid ( ) const
inline

Definition at line 98 of file pipeline.h.

98 { return empty_.IsValid() && available_.IsValid(); }
bool IsValid() const
Definition: semaphore.cc:153

◆ Produce()

template<class R>
ProducerContinuation flutter::Pipeline< R >::Produce ( )
inline

Definition at line 100 of file pipeline.h.

References FML_TRACE_COUNTER, and flutter::GetNextPipelineTraceID().

Referenced by flutter::testing::TEST().

100  {
101  if (!empty_.TryWait()) {
102  return {};
103  }
104  ++inflight_;
105  FML_TRACE_COUNTER("flutter", "Pipeline Depth",
106  reinterpret_cast<int64_t>(this), //
107  "frames in flight", inflight_.load() //
108  );
109 
110  return ProducerContinuation{
111  std::bind(&Pipeline::ProducerCommit, this, std::placeholders::_1,
112  std::placeholders::_2), // continuation
113  GetNextPipelineTraceID()}; // trace id
114  }
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)
Definition: trace_event.h:67
size_t GetNextPipelineTraceID()
Definition: pipeline.cc:9
bool TryWait()
Definition: semaphore.cc:157

◆ ProduceIfEmpty()

template<class R>
ProducerContinuation flutter::Pipeline< R >::ProduceIfEmpty ( )
inline

Definition at line 120 of file pipeline.h.

References FML_TRACE_COUNTER, and flutter::GetNextPipelineTraceID().

Referenced by flutter::testing::TEST().

120  {
121  if (!empty_.TryWait()) {
122  return {};
123  }
124  ++inflight_;
125  FML_TRACE_COUNTER("flutter", "Pipeline Depth",
126  reinterpret_cast<int64_t>(this), //
127  "frames in flight", inflight_.load() //
128  );
129 
130  return ProducerContinuation{
131  std::bind(&Pipeline::ProducerCommitIfEmpty, this, std::placeholders::_1,
132  std::placeholders::_2), // continuation
133  GetNextPipelineTraceID()}; // trace id
134  }
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)
Definition: trace_event.h:67
size_t GetNextPipelineTraceID()
Definition: pipeline.cc:9
bool TryWait()
Definition: semaphore.cc:157

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