Skip to content

Commit 3b235e3

Browse files
peter-mitsisnashif
authored andcommitted
doc: Document pipe flush routines
Adds documentation for the two new flush routines: k_pipe_buffer_flush() k_pipe_flush() Signed-off-by: Peter Mitsis <[email protected]>
1 parent 192265c commit 3b235e3

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

doc/reference/kernel/data_passing/pipes.rst

+57-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ and then pend in the hope that the receive can be completed later. Accepted
4141
data is either copied from the pipe's ring buffer or directly from the
4242
waiting sender(s).
4343

44+
Data may also be **flushed** from a pipe by a thread. Flushing can be performed
45+
either on the entire pipe or on only its ring buffer. Flushing the entire pipe
46+
is equivalent to reading all the information in the ring buffer **and** waiting
47+
to be written into a giant temporary buffer which is then discarded. Flushing
48+
the ring buffer is equivalent to reading **only** the data in the ring buffer
49+
into a temporary buffer which is then discarded. Flushing the ring buffer does
50+
not guarantee that the ring buffer will stay empty; flushing it may allow a
51+
pended writer to fill the ring buffer.
52+
53+
.. note::
54+
Flushing does not in practice allocate or use additional buffers.
55+
4456
.. note::
4557
The kernel does NOT allow for an ISR to send or receive data to/from a
46-
pipe even if it does not attempt to wait for space/data.
58+
pipe or flush even if it does not attempt to wait for space/data.
4759

4860
Implementation
4961
**************
@@ -152,16 +164,57 @@ process data items generated by one or more producing threads.
152164
}
153165
}
154166
155-
Suggested uses
156-
**************
157-
158167
Use a pipe to send streams of data between threads.
159168

160169
.. note::
161170
A pipe can be used to transfer long streams of data if desired. However
162171
it is often preferable to send pointers to large data items to avoid
163172
copying the data.
164173

174+
Flushing a Pipe's Buffer
175+
========================
176+
177+
Data is flushed from the pipe's ring buffer by calling
178+
:c:func:`k_pipe_buffer_flush`.
179+
180+
The following code builds on the examples above, and flushes the pipe's
181+
buffer.
182+
183+
.. code-block:: c
184+
185+
void monitor_thread(void)
186+
{
187+
while (1) {
188+
...
189+
/* Pipe buffer contains stale data. Flush it. */
190+
k_pipe_buffer_flush(&my_pipe);
191+
...
192+
}
193+
}
194+
195+
Flushing a Pipe
196+
===============
197+
198+
All data in the pipe is flushed by calling :c:func:`k_pipe_flush`.
199+
200+
The following code builds on the examples above, and flushes all the
201+
data in the pipe.
202+
203+
Suggested uses
204+
**************
205+
206+
.. code-block:: c
207+
208+
void monitor_thread(void)
209+
{
210+
while (1) {
211+
...
212+
/* Critical error detected. Flush the entire pipe to reset it. */
213+
k_pipe_flush(&my_pipe);
214+
...
215+
}
216+
}
217+
165218
Configuration Options
166219
*********************
167220

0 commit comments

Comments
 (0)