From 1404722d056f68078f681ab7ef597c2491e4633e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 17 Mar 2023 13:38:55 -0700 Subject: [PATCH] Add doc comment to Pipeline (flutter/engine#40388) Add doc comment to Pipeline --- .../flutter/fml/synchronization/semaphore.h | 2 +- engine/src/flutter/shell/common/pipeline.h | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/fml/synchronization/semaphore.h b/engine/src/flutter/fml/synchronization/semaphore.h index b88be468ee..38d1488d64 100644 --- a/engine/src/flutter/fml/synchronization/semaphore.h +++ b/engine/src/flutter/fml/synchronization/semaphore.h @@ -67,7 +67,7 @@ class Semaphore { /// Which makes doing the validity check before this call doubly /// important. /// - /// @return If the count could be decrement. + /// @return If the count could be decremented. /// [[nodiscard]] bool TryWait(); diff --git a/engine/src/flutter/shell/common/pipeline.h b/engine/src/flutter/shell/common/pipeline.h index e8b17768cb..1de4498e7f 100644 --- a/engine/src/flutter/shell/common/pipeline.h +++ b/engine/src/flutter/shell/common/pipeline.h @@ -35,7 +35,29 @@ enum class PipelineConsumeResult { size_t GetNextPipelineTraceID(); /// A thread-safe queue of resources for a single consumer and a single -/// producer. +/// producer, with a maximum queue depth. +/// +/// Pipelines support two key operations: produce and consume. +/// +/// The consumer calls |Consume| to wait for a resource to be produced and +/// consume it when ready. +/// +/// The producer calls |Produce| to generate a `ProducerContinuation` which +/// provides a means to enqueue a resource in the pipeline, if the pipeline is +/// below its maximum depth. When the resource has been prepared, the producer +/// calls `Complete` on the continuation, which enqueues the resource and +/// signals the waiting consumer. +/// +/// Pipelines generate the following tracing information: +/// * PipelineItem: async flow tracking time taken from the time a producer +/// calls |Produce| to the time a consumer consumes calls |Consume|. +/// * PipelineProduce: async flow tracking time taken from the time a producer +/// calls |Produce| to the time they complete the `ProducerContinuation` with +/// a resource. +/// * Pipeline Depth: counter of inflight resource producers. +/// +/// The primary use of this class is as the frame pipeline used in Flutter's +/// animator/rasterizer. template class Pipeline { public: @@ -70,6 +92,7 @@ class Pipeline { } } + /// Completes the continuation with the specified resource. [[nodiscard]] PipelineProduceResult Complete(ResourcePtr resource) { PipelineProduceResult result; if (continuation_) { @@ -108,6 +131,11 @@ class Pipeline { bool IsValid() const { return empty_.IsValid() && available_.IsValid(); } + /// Creates a `ProducerContinuation` that a producer can use to add a + /// resource to the queue. + /// + /// If the queue is already at its maximum depth, the `ProducerContinuation` + /// is returned with success = false. ProducerContinuation Produce() { if (!empty_.TryWait()) { return {}; @@ -124,10 +152,11 @@ class Pipeline { GetNextPipelineTraceID()}; // trace id } - // Create a `ProducerContinuation` that will only push the task if the queue - // is empty. - // Prefer using |Produce|. ProducerContinuation returned by this method - // doesn't guarantee that the frame will be rendered. + /// Creates a `ProducerContinuation` that will only push the task if the + /// queue is empty. + /// + /// Prefer using |Produce|. ProducerContinuation returned by this method + /// doesn't guarantee that the frame will be rendered. ProducerContinuation ProduceIfEmpty() { if (!empty_.TryWait()) { return {}; @@ -186,6 +215,8 @@ class Pipeline { std::mutex queue_mutex_; std::deque> queue_; + /// Commits a produced resource to the queue and signals the consumer that a + /// resource is available. PipelineProduceResult ProducerCommit(ResourcePtr resource, size_t trace_id) { bool is_first_item = false; {