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

Function rt_pipe_create

components/drivers/ipc/pipe.c:617–671  ·  view source on GitHub ↗

* @brief This function will initialize a pipe device. * The system allocates a pipe handle from dynamic heap memory, initializes the pipe handle * with the specified value, and registers the pipe device with the system. * * @param name is the name of pipe device. * * @param bufsz is the size of pipe buffer. * * @return Return the pointer to the pipe device.

Source from the content-addressed store, hash-verified

615 * When the return value is RT_NULL, it means the initialization failed.
616 */
617rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
618{
619 rt_pipe_t *pipe;
620 rt_device_t dev;
621
622 RT_ASSERT(name != RT_NULL);
623 RT_ASSERT(bufsz < 0xFFFF);
624
625 if (rt_device_find(name) != RT_NULL)
626 {
627 /* pipe device has been created */
628 return RT_NULL;
629 }
630 pipe = (rt_pipe_t *)rt_malloc(sizeof(rt_pipe_t));
631 if (pipe == RT_NULL) return RT_NULL;
632
633 rt_memset(pipe, 0, sizeof(rt_pipe_t));
634 pipe->is_named = RT_TRUE; /* initialize as a named pipe */
635#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
636 pipe->pipeno = -1;
637#endif
638 rt_mutex_init(&pipe->lock, name, RT_IPC_FLAG_FIFO);
639 rt_wqueue_init(&pipe->reader_queue);
640 rt_wqueue_init(&pipe->writer_queue);
641 rt_condvar_init(&pipe->waitfor_parter, "piwfp");
642
643 pipe->writer = 0;
644 pipe->reader = 0;
645
646 pipe->bufsz = bufsz;
647
648 dev = &pipe->parent;
649 dev->type = RT_Device_Class_Pipe;
650#ifdef RT_USING_DEVICE_OPS
651 dev->ops = &pipe_ops;
652#else
653 dev->init = RT_NULL;
654 dev->open = rt_pipe_open;
655 dev->read = rt_pipe_read;
656 dev->write = rt_pipe_write;
657 dev->close = rt_pipe_close;
658 dev->control = rt_pipe_control;
659#endif
660
661 dev->rx_indicate = RT_NULL;
662 dev->tx_complete = RT_NULL;
663
664 rt_device_register(&pipe->parent, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE);
665
666#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
667 dev->fops = (void *)&pipe_fops;
668#endif
669
670 return pipe;
671}
672
673/**
674 * @brief This function will delete a pipe device.

Callers 2

pipeFunction · 0.85
mkfifoFunction · 0.85

Calls 7

rt_device_findFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
rt_mutex_initFunction · 0.85
rt_wqueue_initFunction · 0.85
rt_condvar_initFunction · 0.85
rt_device_registerFunction · 0.85

Tested by

no test coverage detected