@@ -41,9 +41,21 @@ and then pend in the hope that the receive can be completed later. Accepted
41
41
data is either copied from the pipe's ring buffer or directly from the
42
42
waiting sender(s).
43
43
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
+
44
56
.. note ::
45
57
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.
47
59
48
60
Implementation
49
61
**************
@@ -152,16 +164,57 @@ process data items generated by one or more producing threads.
152
164
}
153
165
}
154
166
155
- Suggested uses
156
- **************
157
-
158
167
Use a pipe to send streams of data between threads.
159
168
160
169
.. note ::
161
170
A pipe can be used to transfer long streams of data if desired. However
162
171
it is often preferable to send pointers to large data items to avoid
163
172
copying the data.
164
173
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
+
165
218
Configuration Options
166
219
*********************
167
220
0 commit comments