|
ginnOS
The reference: libc, the libraries and the kernel
|
Go to the source code of this file.
Data Structures | |
| struct | pipe_buf |
| a pipe. More... | |
Macros | |
| #define | PIPE_CAPACITY 16384 |
| pipes: a ring buffer shared by a read end and a write end. | |
| #define | PIPE_BUF 4096 |
Typedefs | |
| typedef struct pipe_buf | pipe_buf_t |
| a pipe. | |
Enumerations | |
| enum | pipe_dir_t { PIPE_READ = 0 , PIPE_WRITE = 1 } |
| pipe endpoint direction. More... | |
Functions | |
| pipe_buf_t * | pipe_alloc (void) |
| allocate a pipe with one open read end and one open write end. | |
| void | pipe_ref (pipe_buf_t *pipe, pipe_dir_t dir) |
| open another end of a pipe (dup2 or fd inheritance). | |
| void | pipe_unref (pipe_buf_t *pipe, pipe_dir_t dir) |
| close one end of a pipe. | |
| int32_t | pipe_read (pipe_buf_t *pipe, char *buf, uint32_t count, bool nonblock) |
| read from a pipe, sleeping while it is empty and a write end is open. | |
| int32_t | pipe_write (pipe_buf_t *pipe, const char *buf, uint32_t count, bool nonblock) |
| write every byte to a pipe, sleeping whenever it is full. | |
| uint32_t | pipe_poll (pipe_buf_t *pipe, pipe_dir_t dir) |
| the readiness of one end of a pipe: the read end has POLLIN when there is data or no writer is left (POLLHUP then too); the write end has POLLOUT when PIPE_BUF bytes fit, and POLLERR when no reader is left. | |
| #define PIPE_CAPACITY 16384 |
pipes: a ring buffer shared by a read end and a write end.
each pipe and its buffer come from the kernel heap, so the number of pipes is limited only by memory (and by the fds that hold their ends).
a write of at most PIPE_BUF bytes is atomic: it waits until there is room for all of it, so its bytes are never mixed with another writer's. larger writes can be split.
every field of a pipe is guarded by its spinlock, so reads, writes and reference changes are atomic against preemption (syscalls run with interrupts enabled). readers and writers that must wait sleep on the pipe's wait queues with wait_queue_block_locked(), which releases the lock atomically, so a wakeup between the check and the sleep is never lost.
| #define PIPE_BUF 4096 |
| typedef struct pipe_buf pipe_buf_t |
a pipe.
shared between all of its read and write ends.
| enum pipe_dir_t |
| pipe_buf_t * pipe_alloc | ( | void | ) |
allocate a pipe with one open read end and one open write end.
| void pipe_ref | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
open another end of a pipe (dup2 or fd inheritance).
| pipe | the pipe. |
| dir | which end the new reference is. |
| void pipe_unref | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
close one end of a pipe.
closing the last read end wakes blocked writers (they then see a broken pipe); closing the last write end wakes blocked readers (they then see EOF). the pipe is freed once both ends are fully closed.
| pipe | the pipe. |
| dir | which end is being closed. |
| int32_t pipe_read | ( | pipe_buf_t * | pipe, |
| char * | buf, | ||
| uint32_t | count, | ||
| bool | nonblock ) |
read from a pipe, sleeping while it is empty and a write end is open.
| pipe | the pipe. |
| buf | destination buffer. |
| count | maximum number of bytes to read (> 0). |
| nonblock | return -EAGAIN instead of sleeping. |
| int32_t pipe_write | ( | pipe_buf_t * | pipe, |
| const char * | buf, | ||
| uint32_t | count, | ||
| bool | nonblock ) |
write every byte to a pipe, sleeping whenever it is full.
a write of at most PIPE_BUF bytes goes in as one piece.
| pipe | the pipe. |
| buf | source buffer. |
| count | number of bytes to write (> 0). |
| nonblock | stop instead of sleeping when the pipe is full. |
| uint32_t pipe_poll | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
the readiness of one end of a pipe: the read end has POLLIN when there is data or no writer is left (POLLHUP then too); the write end has POLLOUT when PIPE_BUF bytes fit, and POLLERR when no reader is left.
| pipe | the pipe. |
| dir | which end. |