diff options
Diffstat (limited to 'libpipe/pipe.h')
-rw-r--r-- | libpipe/pipe.h | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/libpipe/pipe.h b/libpipe/pipe.h index cc765dc6..96432990 100644 --- a/libpipe/pipe.h +++ b/libpipe/pipe.h @@ -24,8 +24,16 @@ #define EWOULDBLOCK EAGAIN /* XXX */ #include <cthreads.h> /* For conditions & mutexes */ +#include <features.h> + +#ifdef PIPE_DEFINE_EI +#define PIPE_EI +#else +#define PIPE_EI __extern_inline +#endif #include "pq.h" + /* A description of a class of pipes and how to operate on them. */ struct pipe_class @@ -93,7 +101,7 @@ struct pipe PACKET_TYPE_CONTROL. Each data packet represents one datagram for protocols that maintain record boundaries. Control packets always represent the control information to be returned from one read - operation, and will be returned in conjuction with the following data + operation, and will be returned in conjunction with the following data packet (if any). Reads interested only in data just skip control packets until they find a data packet. */ struct pq *queue; @@ -102,9 +110,24 @@ struct pipe /* Pipe flags. */ #define PIPE_BROKEN 0x1 /* This pipe isn't connected. */ + +extern size_t pipe_readable (struct pipe *pipe, int data_only); + +extern int pipe_is_readable (struct pipe *pipe, int data_only); + +extern error_t pipe_wait_readable (struct pipe *pipe, int noblock, int data_only); + +extern error_t pipe_select_readable (struct pipe *pipe, int data_only); + +extern error_t pipe_wait_writable (struct pipe *pipe, int noblock); + +extern error_t pipe_select_writable (struct pipe *pipe); + +#if defined(__USE_EXTERN_INLINES) || defined(PIPE_DEFINE_EI) + /* Returns the number of characters quickly readable from PIPE. If DATA_ONLY is true, then `control' packets are ignored. */ -extern inline size_t +PIPE_EI size_t pipe_readable (struct pipe *pipe, int data_only) { size_t readable = 0; @@ -123,7 +146,7 @@ pipe_readable (struct pipe *pipe, int data_only) then `control' packets are ignored. Note that this is different than (pipe_readable (PIPE) > 0) in the case where a control packet containing only ports is present. */ -extern inline int +PIPE_EI int pipe_is_readable (struct pipe *pipe, int data_only) { struct pq *pq = pipe->queue; @@ -134,11 +157,11 @@ pipe_is_readable (struct pipe *pipe, int data_only) return (packet != NULL); } -/* Waits for PIPE to be readable, or an error to occurr. If NOBLOCK is true, +/* Waits for PIPE to be readable, or an error to occur. If NOBLOCK is true, this operation will return EWOULDBLOCK instead of blocking when no data is immediately available. If DATA_ONLY is true, then `control' packets are ignored. */ -extern inline error_t +PIPE_EI error_t pipe_wait_readable (struct pipe *pipe, int noblock, int data_only) { while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN)) @@ -151,11 +174,11 @@ pipe_wait_readable (struct pipe *pipe, int noblock, int data_only) return 0; } -/* Waits for PIPE to be readable, or an error to occurr. This call only +/* Waits for PIPE to be readable, or an error to occur. This call only returns once threads waiting using pipe_wait_readable have been woken and given a chance to read, and if there is still data available thereafter. If DATA_ONLY is true, then `control' packets are ignored. */ -extern inline error_t +PIPE_EI error_t pipe_select_readable (struct pipe *pipe, int data_only) { while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN)) @@ -167,7 +190,7 @@ pipe_select_readable (struct pipe *pipe, int data_only) /* Block until data can be written to PIPE. If NOBLOCK is true, then EWOULDBLOCK is returned instead of blocking if this can't be done immediately. */ -extern inline error_t +PIPE_EI error_t pipe_wait_writable (struct pipe *pipe, int noblock) { size_t limit = pipe->write_limit; @@ -188,7 +211,7 @@ pipe_wait_writable (struct pipe *pipe, int noblock) /* Block until some data can be written to PIPE. This call only returns once threads waiting using pipe_wait_writable have been woken and given a chance to write, and if there is still space available thereafter. */ -extern inline error_t +PIPE_EI error_t pipe_select_writable (struct pipe *pipe) { size_t limit = pipe->write_limit; @@ -198,6 +221,8 @@ pipe_select_writable (struct pipe *pipe) return 0; } +#endif /* Use extern inlines. */ + /* Creates a new pipe of class CLASS and returns it in RESULT. */ error_t pipe_create (struct pipe_class *class, struct pipe **pipe); @@ -218,8 +243,28 @@ void _pipe_no_readers (struct pipe *pipe); should be locked. */ void _pipe_no_writers (struct pipe *pipe); +extern void pipe_acquire_reader (struct pipe *pipe); + +extern void pipe_acquire_writer (struct pipe *pipe); + +extern void pipe_release_reader (struct pipe *pipe); + +extern void pipe_release_writer (struct pipe *pipe); + +extern void pipe_add_reader (struct pipe *pipe); + +extern void pipe_add_writer (struct pipe *pipe); + +extern void pipe_remove_reader (struct pipe *pipe); + +extern void pipe_remove_writer (struct pipe *pipe); + +extern void pipe_drain (struct pipe *pipe); + +#if defined(__USE_EXTERN_INLINES) || defined(PIPE_DEFINE_EI) + /* Lock PIPE and increment its readers count. */ -extern inline void +PIPE_EI void pipe_acquire_reader (struct pipe *pipe) { mutex_lock (&pipe->lock); @@ -228,7 +273,7 @@ pipe_acquire_reader (struct pipe *pipe) } /* Lock PIPE and increment its writers count. */ -extern inline void +PIPE_EI void pipe_acquire_writer (struct pipe *pipe) { mutex_lock (&pipe->lock); @@ -238,7 +283,7 @@ pipe_acquire_writer (struct pipe *pipe) /* Decrement PIPE's (which should be locked) reader count and unlock it. If there are no more refs to PIPE, it will be destroyed. */ -extern inline void +PIPE_EI void pipe_release_reader (struct pipe *pipe) { if (--pipe->readers == 0) @@ -249,7 +294,7 @@ pipe_release_reader (struct pipe *pipe) /* Decrement PIPE's (which should be locked) writer count and unlock it. If there are no more refs to PIPE, it will be destroyed. */ -extern inline void +PIPE_EI void pipe_release_writer (struct pipe *pipe) { if (--pipe->writers == 0) @@ -259,7 +304,7 @@ pipe_release_writer (struct pipe *pipe) } /* Increment PIPE's reader count. PIPE should be unlocked. */ -extern inline void +PIPE_EI void pipe_add_reader (struct pipe *pipe) { pipe_acquire_reader (pipe); @@ -267,7 +312,7 @@ pipe_add_reader (struct pipe *pipe) } /* Increment PIPE's writer count. PIPE should be unlocked. */ -extern inline void +PIPE_EI void pipe_add_writer (struct pipe *pipe) { pipe_acquire_writer (pipe); @@ -276,7 +321,7 @@ pipe_add_writer (struct pipe *pipe) /* Decrement PIPE's (which should be unlocked) reader count and unlock it. If there are no more refs to PIPE, it will be destroyed. */ -extern inline void +PIPE_EI void pipe_remove_reader (struct pipe *pipe) { mutex_lock (&pipe->lock); @@ -285,7 +330,7 @@ pipe_remove_reader (struct pipe *pipe) /* Decrement PIPE's (which should be unlocked) writer count and unlock it. If there are no more refs to PIPE, it will be destroyed. */ -extern inline void +PIPE_EI void pipe_remove_writer (struct pipe *pipe) { mutex_lock (&pipe->lock); @@ -293,12 +338,14 @@ pipe_remove_writer (struct pipe *pipe) } /* Empty out PIPE of any data. PIPE should be locked. */ -extern inline void +PIPE_EI void pipe_drain (struct pipe *pipe) { pq_drain (pipe->queue); } +#endif /* Use extern inlines. */ + /* Writes up to LEN bytes of DATA, to PIPE, which should be locked, and returns the amount written in AMOUNT. If present, the information in CONTROL & PORTS is written in a preceding control packet. If an error is |