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

Function pipe_fops_close

components/drivers/ipc/pipe.c:121–167  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

119 * When the return value is -1, it means the file descriptor is invalid.
120 */
121static 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.

Callers

nothing calls this directly

Calls 6

rt_mutex_takeFunction · 0.85
rt_list_isemptyFunction · 0.85
rt_wqueue_wakeupFunction · 0.85
rt_ringbuffer_destroyFunction · 0.85
rt_mutex_releaseFunction · 0.85
rt_pipe_deleteFunction · 0.85

Tested by

no test coverage detected