| 282 | static ssize_t pipe_fops_write(struct dfs_file *fd, const void *buf, size_t count, off_t *pos) |
| 283 | #else |
| 284 | static ssize_t pipe_fops_write(struct dfs_file *fd, const void *buf, size_t count) |
| 285 | #endif |
| 286 | { |
| 287 | int len; |
| 288 | rt_pipe_t *pipe; |
| 289 | int wakeup = 0; |
| 290 | int ret = 0; |
| 291 | uint8_t *pbuf; |
| 292 | |
| 293 | pipe = (rt_pipe_t *)fd->vnode->data; |
| 294 | |
| 295 | if (count == 0) |
| 296 | { |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | pbuf = (uint8_t*)buf; |
| 301 | rt_mutex_take(&pipe->lock, -1); |
| 302 | |
| 303 | while (1) |
| 304 | { |
| 305 | len = rt_ringbuffer_put(pipe->fifo, pbuf, count - ret); |
| 306 | ret += len; |
| 307 | pbuf += len; |
| 308 | wakeup = 1; |
| 309 | |
| 310 | if (ret == count) |
| 311 | { |
| 312 | break; |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | if (fd->flags & O_NONBLOCK) |
| 317 | { |
| 318 | if (ret == 0) |
| 319 | { |
| 320 | ret = -EAGAIN; |
| 321 | } |
| 322 | |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | rt_mutex_release(&pipe->lock); |
| 328 | rt_wqueue_wakeup(&pipe->reader_queue, (void*)POLLIN); |
| 329 | /* pipe full, waiting on suspended write list */ |
| 330 | if (rt_wqueue_wait_interruptible(&pipe->writer_queue, 0, -1) == -RT_EINTR) |
| 331 | return -EINTR; |
| 332 | rt_mutex_take(&pipe->lock, -1); |
| 333 | } |
| 334 | rt_mutex_release(&pipe->lock); |
| 335 | |
| 336 | if (wakeup) |
| 337 | { |
| 338 | rt_wqueue_wakeup(&pipe->reader_queue, (void*)POLLIN); |
| 339 | } |
| 340 | |
| 341 | return ret; |
nothing calls this directly
no test coverage detected