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

Function rt_pipe_open

components/drivers/ipc/pipe.c:426–452  ·  view source on GitHub ↗

* @brief This function will open the pipe and actually creates the pipe buffer. * * @param device is a pointer to the pipe device descriptor. * * @param oflag is the open method, but it is not used yet. * * @return Return the operation status. * When the return value is RT_EOK, the operation is successful. * When the return value is -RT_EINVAL, it means the d

Source from the content-addressed store, hash-verified

424 * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
425 */
426rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
427{
428 rt_pipe_t *pipe = (rt_pipe_t *)device;
429 rt_err_t ret = RT_EOK;
430
431 if (device == RT_NULL)
432 {
433 ret = -RT_EINVAL;
434 goto __exit;
435 }
436
437 rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
438
439 if (pipe->fifo == RT_NULL)
440 {
441 pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
442 if (pipe->fifo == RT_NULL)
443 {
444 ret = -RT_ENOMEM;
445 }
446 }
447
448 rt_mutex_release(&pipe->lock);
449
450__exit:
451 return ret;
452}
453
454/**
455 * @brief This function will close the pipe and release the pipe buffer.

Callers

nothing calls this directly

Calls 3

rt_mutex_takeFunction · 0.85
rt_ringbuffer_createFunction · 0.85
rt_mutex_releaseFunction · 0.85

Tested by

no test coverage detected