| 223 | static ssize_t pipe_fops_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos) |
| 224 | #else |
| 225 | static 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 | |
| 263 | out: |
| 264 | rt_mutex_release(&pipe->lock); |
| 265 | return len; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @brief This function will write data to pipe. |
nothing calls this directly
no test coverage detected