Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 66aff63

Browse files
committed
Add doc comment to Pipeline
Adds more detailed documentation to the Pipeline class. Also fixes a typo in fml::Semaphore docs.
1 parent a5e3627 commit 66aff63

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

fml/synchronization/semaphore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Semaphore {
6767
/// Which makes doing the validity check before this call doubly
6868
/// important.
6969
///
70-
/// @return If the count could be decrement.
70+
/// @return If the count could be decremented.
7171
///
7272
[[nodiscard]] bool TryWait();
7373

shell/common/pipeline.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ size_t GetNextPipelineTraceID();
3636

3737
/// A thread-safe queue of resources for a single consumer and a single
3838
/// producer.
39+
///
40+
/// Pipelines support two key operations: produce and consume.
41+
///
42+
/// The consumer calls `Consume` to wait for a resource to be produced and
43+
/// consume it when ready.
44+
///
45+
/// The producer calls `Produce` to generate a `ProducerContinuation` which
46+
/// provides a means to enqueue a resource in the pipeline. When the resource
47+
/// has been prepared, the producer calls `Complete` on the continuation, which
48+
/// enqueues the resource and signals the waiting consumer.
49+
///
50+
/// Pipelines generate the following tracing information:
51+
/// * PipelineProduce: async flow tracking time taken to produce a resource.
52+
/// * Pipeline Depth: counter of inflight resource producers.
3953
template <class R>
4054
class Pipeline {
4155
public:
@@ -70,6 +84,7 @@ class Pipeline {
7084
}
7185
}
7286

87+
/// Completes the continuation with the specified resource.
7388
[[nodiscard]] PipelineProduceResult Complete(ResourcePtr resource) {
7489
PipelineProduceResult result;
7590
if (continuation_) {
@@ -108,6 +123,8 @@ class Pipeline {
108123

109124
bool IsValid() const { return empty_.IsValid() && available_.IsValid(); }
110125

126+
// Creates a `ProducerContinuation` that a producer can use to add a resource
127+
// to the queue.
111128
ProducerContinuation Produce() {
112129
if (!empty_.TryWait()) {
113130
return {};
@@ -124,8 +141,9 @@ class Pipeline {
124141
GetNextPipelineTraceID()}; // trace id
125142
}
126143

127-
// Create a `ProducerContinuation` that will only push the task if the queue
144+
// Creates a `ProducerContinuation` that will only push the task if the queue
128145
// is empty.
146+
//
129147
// Prefer using |Produce|. ProducerContinuation returned by this method
130148
// doesn't guarantee that the frame will be rendered.
131149
ProducerContinuation ProduceIfEmpty() {
@@ -186,6 +204,7 @@ class Pipeline {
186204
std::mutex queue_mutex_;
187205
std::deque<std::pair<ResourcePtr, size_t>> queue_;
188206

207+
/// Commits a produced resource to the queue and signals the consumer.
189208
PipelineProduceResult ProducerCommit(ResourcePtr resource, size_t trace_id) {
190209
bool is_first_item = false;
191210
{

0 commit comments

Comments
 (0)