MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pipe_fops_read

Function pipe_fops_read

components/drivers/ipc/pipe.c:225–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223static ssize_t pipe_fops_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos)
224#else
225static ssize_t pipe_fops_read(struct dfs_file *fd, void *buf, size_t count)
226#endif
227{
228 int len = 0;
229 rt_pipe_t *pipe;
230
231 pipe = (rt_pipe_t *)fd->vnode->data;
232
233 /* no process has the pipe open for writing, return end-of-file */
234 rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
235
236 while (1)
237 {
238 len = rt_ringbuffer_get(pipe->fifo, buf, count);
239
240 if (len > 0 || pipe->writer == 0)
241 {
242 break;
243 }
244 else
245 {
246 if (fd->flags & O_NONBLOCK)
247 {
248 len = -EAGAIN;
249 goto out;
250 }
251
252 rt_mutex_release(&pipe->lock);
253 rt_wqueue_wakeup(&pipe->writer_queue, (void*)POLLOUT);
254 if (rt_wqueue_wait_interruptible(&pipe->reader_queue, 0, -1) == -RT_EINTR)
255 return -EINTR;
256 rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
257 }
258 }
259
260 /* wakeup writer */
261 rt_wqueue_wakeup(&pipe->writer_queue, (void*)POLLOUT);
262
263out:
264 rt_mutex_release(&pipe->lock);
265 return len;
266}
267
268/**
269 * @brief This function will write data to pipe.

Callers

nothing calls this directly

Calls 5

rt_mutex_takeFunction · 0.85
rt_ringbuffer_getFunction · 0.85
rt_mutex_releaseFunction · 0.85
rt_wqueue_wakeupFunction · 0.85

Tested by

no test coverage detected