* @brief This function will close a pipe. * * @param fd is the file descriptor. * * @return Return the operation status. * When the return value is 0, it means the operation is successful. * When the return value is -1, it means the file descriptor is invalid. */
| 119 | * When the return value is -1, it means the file descriptor is invalid. |
| 120 | */ |
| 121 | static int pipe_fops_close(struct dfs_file *fd) |
| 122 | { |
| 123 | rt_device_t device; |
| 124 | rt_pipe_t *pipe; |
| 125 | |
| 126 | pipe = (rt_pipe_t *)fd->vnode->data; |
| 127 | if (!pipe) |
| 128 | { |
| 129 | return -1; |
| 130 | } |
| 131 | |
| 132 | device = &pipe->parent; |
| 133 | rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER); |
| 134 | |
| 135 | if ((fd->flags & O_RDONLY) == O_RDONLY) |
| 136 | { |
| 137 | pipe->reader -= 1; |
| 138 | } |
| 139 | |
| 140 | if ((fd->flags & O_WRONLY) == O_WRONLY) |
| 141 | { |
| 142 | pipe->writer -= 1; |
| 143 | while (!rt_list_isempty(&pipe->reader_queue.waiting_list)) |
| 144 | { |
| 145 | rt_wqueue_wakeup(&pipe->reader_queue, (void*)POLLIN); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (fd->vnode->ref_count == 1) |
| 150 | { |
| 151 | if (pipe->fifo != RT_NULL) |
| 152 | { |
| 153 | rt_ringbuffer_destroy(pipe->fifo); |
| 154 | } |
| 155 | pipe->fifo = RT_NULL; |
| 156 | } |
| 157 | |
| 158 | rt_mutex_release(&pipe->lock); |
| 159 | |
| 160 | if (fd->vnode->ref_count == 1 && pipe->is_named == RT_FALSE) |
| 161 | { |
| 162 | /* delete the unamed pipe */ |
| 163 | rt_pipe_delete(device->parent.name); |
| 164 | } |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @brief This function will get the pipe space size depends on the command. |
nothing calls this directly
no test coverage detected