pipe.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * RT-Thread RuiChing
  3. *
  4. * COPYRIGHT (C) 2024-2025 Shanghai Real-Thread Electronic Technology Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * The license and distribution terms for this file may be
  8. * found in the file LICENSE in this distribution.
  9. */
  10. #ifndef __PIPE_H__
  11. #define __PIPE_H__
  12. #include <kpi.h>
  13. #include <rtconfig.h>
  14. #include <rtdef.h>
  15. #include "condvar.h"
  16. /**
  17. * Pipe Device
  18. */
  19. struct rt_pipe_device
  20. {
  21. struct rt_device parent;
  22. rt_bool_t is_named;
  23. #ifdef RT_USING_POSIX_DEVIO
  24. int pipeno; /* for unamed pipe */
  25. #endif
  26. /* ring buffer in pipe device */
  27. struct rt_ringbuffer *fifo;
  28. rt_uint16_t bufsz;
  29. rt_wqueue_t reader_queue;
  30. rt_wqueue_t writer_queue;
  31. int writer;
  32. int reader;
  33. struct rt_condvar waitfor_parter;
  34. struct rt_mutex lock;
  35. };
  36. typedef struct rt_pipe_device rt_pipe_t;
  37. typedef rt_pipe_t *(*__kpi_rt_pipe_create)(const char *name, int bufsz);
  38. typedef rt_err_t (*__kpi_rt_pipe_open)(rt_device_t device, rt_uint16_t oflag);
  39. typedef rt_ssize_t (*__kpi_rt_pipe_read)(
  40. rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count);
  41. typedef rt_ssize_t (*__kpi_rt_pipe_write)(
  42. rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count);
  43. typedef rt_err_t (*__kpi_rt_pipe_control)(rt_device_t dev, int cmd, void *args);
  44. typedef rt_err_t (*__kpi_rt_pipe_close)(rt_device_t device);
  45. typedef int (*__kpi_rt_pipe_delete)(const char *name);
  46. KPI_EXTERN(rt_pipe_create);
  47. KPI_EXTERN(rt_pipe_open);
  48. KPI_EXTERN(rt_pipe_read);
  49. KPI_EXTERN(rt_pipe_write);
  50. KPI_EXTERN(rt_pipe_control);
  51. KPI_EXTERN(rt_pipe_close);
  52. KPI_EXTERN(rt_pipe_delete);
  53. #endif /* __PIPE_H__ */