@@ -557,7 +557,7 @@ rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, r
557
557
}
558
558
559
559
pbuf = (uint8_t * )buffer ;
560
- rt_mutex_take (& pipe -> lock , -1 );
560
+ rt_mutex_take (& pipe -> lock , RT_WAITING_FOREVER );
561
561
562
562
while (write_bytes < count )
563
563
{
@@ -619,6 +619,14 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
619
619
rt_pipe_t * pipe ;
620
620
rt_device_t dev ;
621
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
+ }
622
630
pipe = (rt_pipe_t * )rt_malloc (sizeof (rt_pipe_t ));
623
631
if (pipe == RT_NULL ) return RT_NULL ;
624
632
@@ -635,7 +643,6 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
635
643
pipe -> writer = 0 ;
636
644
pipe -> reader = 0 ;
637
645
638
- RT_ASSERT (bufsz < 0xFFFF );
639
646
pipe -> bufsz = bufsz ;
640
647
641
648
dev = & pipe -> parent ;
@@ -654,15 +661,8 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
654
661
dev -> rx_indicate = RT_NULL ;
655
662
dev -> tx_complete = RT_NULL ;
656
663
657
- if (rt_device_register (& pipe -> parent , name , RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE ) != 0 )
658
- {
659
- rt_mutex_detach (& pipe -> lock );
660
- #if defined(RT_USING_POSIX_DEVIO ) && defined(RT_USING_POSIX_PIPE )
661
- resource_id_put (& id_mgr , pipe -> pipeno );
662
- #endif
663
- rt_free (pipe );
664
- return RT_NULL ;
665
- }
664
+ rt_device_register (& pipe -> parent , name , RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
665
+
666
666
#if defined(RT_USING_POSIX_DEVIO ) && defined(RT_USING_POSIX_PIPE )
667
667
dev -> fops = (void * )& pipe_fops ;
668
668
#endif
@@ -762,13 +762,15 @@ int pipe(int fildes[2])
762
762
fildes [1 ] = open (dev_name , O_WRONLY , 0 );
763
763
if (fildes [1 ] < 0 )
764
764
{
765
- close ( fildes [ 0 ] );
765
+ rt_pipe_delete ( dname );
766
766
return -1 ;
767
767
}
768
768
769
769
fildes [0 ] = open (dev_name , O_RDONLY , 0 );
770
770
if (fildes [0 ] < 0 )
771
771
{
772
+ close (fildes [1 ]);
773
+ rt_pipe_delete (dname );
772
774
return -1 ;
773
775
}
774
776
0 commit comments