[21242c2] | 1 | /** |
---|
| 2 | * @file rtems/pipe.h |
---|
[e2324c0] | 3 | * |
---|
[9ab091e] | 4 | * @brief Defines the Interface to the POSIX FIFO/pipe File System Support |
---|
| 5 | * |
---|
[21242c2] | 6 | * This include file defines the interface to the POSIX FIFO/pipe file system |
---|
| 7 | * support. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /* |
---|
[e2324c0] | 11 | * Author: Wei Shen <cquark@gmail.com> |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
| 15 | * http://www.rtems.com/license/LICENSE. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #ifndef _RTEMS_PIPE_H |
---|
| 19 | #define _RTEMS_PIPE_H |
---|
| 20 | |
---|
| 21 | #include <rtems/libio.h> |
---|
| 22 | |
---|
[3fa979c] | 23 | #ifdef __cplusplus |
---|
| 24 | extern "C" { |
---|
| 25 | #endif |
---|
| 26 | |
---|
[11109ea] | 27 | /** |
---|
| 28 | * @defgroup FIFO_PIPE FIFO/pipe File System Support |
---|
[9ab091e] | 29 | * |
---|
[11109ea] | 30 | * @brief Interface to the POSIX FIFO/pipe File System |
---|
| 31 | */ |
---|
| 32 | |
---|
[e2324c0] | 33 | /* Control block to manage each pipe */ |
---|
| 34 | typedef struct pipe_control { |
---|
| 35 | char *Buffer; |
---|
[4da0caef] | 36 | unsigned int Size; |
---|
| 37 | unsigned int Start; |
---|
| 38 | unsigned int Length; |
---|
| 39 | unsigned int Readers; |
---|
| 40 | unsigned int Writers; |
---|
| 41 | unsigned int waitingReaders; |
---|
| 42 | unsigned int waitingWriters; |
---|
| 43 | unsigned int readerCounter; /* incremental counters */ |
---|
| 44 | unsigned int writerCounter; /* for differentiation of successive opens */ |
---|
[e2324c0] | 45 | rtems_id Semaphore; |
---|
| 46 | rtems_id readBarrier; /* wait queues */ |
---|
| 47 | rtems_id writeBarrier; |
---|
| 48 | #if 0 |
---|
| 49 | boolean Anonymous; /* anonymous pipe or FIFO */ |
---|
| 50 | #endif |
---|
| 51 | } pipe_control_t; |
---|
| 52 | |
---|
[11109ea] | 53 | /** |
---|
| 54 | * @brief Create an Anonymous Pipe |
---|
[9ab091e] | 55 | * |
---|
[e2324c0] | 56 | * Called by pipe() to create an anonymous pipe. |
---|
| 57 | */ |
---|
[3fa979c] | 58 | extern int pipe_create( |
---|
[e2324c0] | 59 | int filsdes[2] |
---|
| 60 | ); |
---|
| 61 | |
---|
[11109ea] | 62 | /** |
---|
| 63 | * @brief Release a Pipe |
---|
[9ab091e] | 64 | * |
---|
[e2324c0] | 65 | * Interface to file system close. |
---|
| 66 | * |
---|
| 67 | * *pipep points to pipe control structure. When the last user releases pipe, |
---|
| 68 | * it will be set to NULL. |
---|
| 69 | */ |
---|
[8f0b334] | 70 | extern void pipe_release( |
---|
[e2324c0] | 71 | pipe_control_t **pipep, |
---|
| 72 | rtems_libio_t *iop |
---|
| 73 | ); |
---|
| 74 | |
---|
[11109ea] | 75 | /** |
---|
| 76 | * @brief FIFO Open |
---|
[e2324c0] | 77 | * Interface to file system open. |
---|
| 78 | * |
---|
| 79 | * *pipep points to pipe control structure. If called with *pipep = NULL, |
---|
| 80 | * fifo_open will try allocating and initializing a control structure. If the |
---|
| 81 | * call succeeds, *pipep will be set to address of new control structure. |
---|
| 82 | */ |
---|
[3fa979c] | 83 | extern int fifo_open( |
---|
[e2324c0] | 84 | pipe_control_t **pipep, |
---|
| 85 | rtems_libio_t *iop |
---|
| 86 | ); |
---|
| 87 | |
---|
[11109ea] | 88 | /** |
---|
| 89 | * @brief Pipe Read |
---|
[9ab091e] | 90 | * |
---|
[e2324c0] | 91 | * Interface to file system read. |
---|
| 92 | */ |
---|
[3fa979c] | 93 | extern ssize_t pipe_read( |
---|
[e2324c0] | 94 | pipe_control_t *pipe, |
---|
| 95 | void *buffer, |
---|
| 96 | size_t count, |
---|
| 97 | rtems_libio_t *iop |
---|
| 98 | ); |
---|
| 99 | |
---|
[11109ea] | 100 | /** |
---|
| 101 | * @brief Pipe Write |
---|
[9ab091e] | 102 | * |
---|
[e2324c0] | 103 | * Interface to file system write. |
---|
| 104 | */ |
---|
[3fa979c] | 105 | extern ssize_t pipe_write( |
---|
[e2324c0] | 106 | pipe_control_t *pipe, |
---|
| 107 | const void *buffer, |
---|
| 108 | size_t count, |
---|
| 109 | rtems_libio_t *iop |
---|
| 110 | ); |
---|
| 111 | |
---|
[11109ea] | 112 | /** |
---|
| 113 | * @brief Pipe IO Control |
---|
[9ab091e] | 114 | * |
---|
[e2324c0] | 115 | * Interface to file system ioctl. |
---|
| 116 | */ |
---|
[3fa979c] | 117 | extern int pipe_ioctl( |
---|
[df01da67] | 118 | pipe_control_t *pipe, |
---|
| 119 | ioctl_command_t cmd, |
---|
| 120 | void *buffer, |
---|
| 121 | rtems_libio_t *iop |
---|
[e2324c0] | 122 | ); |
---|
| 123 | |
---|
[3fa979c] | 124 | #ifdef __cplusplus |
---|
[0a7278e] | 125 | } |
---|
[3fa979c] | 126 | #endif |
---|
| 127 | |
---|
| 128 | #endif |
---|