aboutsummaryrefslogtreecommitdiff
path: root/libpipe/pq.h
diff options
context:
space:
mode:
Diffstat (limited to 'libpipe/pq.h')
-rw-r--r--libpipe/pq.h68
1 files changed, 56 insertions, 12 deletions
diff --git a/libpipe/pq.h b/libpipe/pq.h
index abd193f8..0fffe254 100644
--- a/libpipe/pq.h
+++ b/libpipe/pq.h
@@ -1,6 +1,6 @@
/* Packet queues
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2006 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -25,6 +25,14 @@
#include <stddef.h> /* for size_t */
#include <string.h>
#include <mach/mach.h>
+#include <features.h>
+
+#ifdef PQ_DEFINE_EI
+#define PQ_EI
+#else
+#define PQ_EI __extern_inline
+#endif
+
struct packet
{
@@ -65,15 +73,21 @@ error_t packet_set_ports (struct packet *packet,
/* If PACKET has any ports, deallocates them. */
void packet_dealloc_ports (struct packet *packet);
+extern size_t packet_readable (struct packet *packet);
+
+#if defined(__USE_EXTERN_INLINES) || defined(PQ_DEFINE_EI)
+
/* Returns the number of bytes of data in PACKET. */
-extern inline size_t
+PQ_EI size_t
packet_readable (struct packet *packet)
{
return packet->buf_end - packet->buf_start;
}
+#endif /* Use extern inlines. */
+
/* Append the bytes in DATA, of length DATA_LEN, to what's already in PACKET,
- and return the amount appended in AMOUNT. */
+ and return the amount appended in AMOUNT if that's not the null pointer. */
error_t packet_write (struct packet *packet,
char *data, size_t data_len, size_t *amount);
@@ -89,14 +103,20 @@ error_t packet_read (struct packet *packet,
error_t packet_read_ports (struct packet *packet,
mach_port_t **ports, size_t *num_ports);
+extern void packet_read_source (struct packet *packet, void **source);
+
+#if defined(__USE_EXTERN_INLINES) || defined(PQ_DEFINE_EI)
+
/* Return the source addressd in PACKET in SOURCE, deallocating it from
PACKET. */
-extern inline void
+PQ_EI void
packet_read_source (struct packet *packet, void **source)
{
*source = packet->source;
packet->source = 0;
}
+
+#endif /* Use extern inlines. */
/* The packet size above which we start to do things differently to avoid
copying around data. */
@@ -120,9 +140,17 @@ int packet_extend (struct packet *packet, size_t new_len);
returned. */
error_t packet_realloc (struct packet *packet, size_t new_len);
+extern int packet_fit (struct packet *packet, size_t amount);
+
+extern error_t packet_ensure (struct packet *packet, size_t amount);
+
+extern int packet_ensure_efficiently (struct packet *packet, size_t amount);
+
+#if defined(__USE_EXTERN_INLINES) || defined(PQ_DEFINE_EI)
+
/* Try to make space in PACKET for AMOUNT more bytes without growing the
buffer, returning true if we could do it. */
-extern inline int
+PQ_EI int
packet_fit (struct packet *packet, size_t amount)
{
char *buf = packet->buf, *end = packet->buf_end;
@@ -154,7 +182,7 @@ packet_fit (struct packet *packet, size_t amount)
/* Make sure that PACKET has room for at least AMOUNT more bytes, or return
the reason why not. */
-extern inline error_t
+PQ_EI error_t
packet_ensure (struct packet *packet, size_t amount)
{
if (! packet_fit (packet, amount))
@@ -171,7 +199,7 @@ packet_ensure (struct packet *packet, size_t amount)
it can be done efficiently, e.g., the packet can be grown in place, rather
than moving the contents (or there is little enough data so that copying
it is OK). True is returned if room was made, false otherwise. */
-extern inline int
+PQ_EI int
packet_ensure_efficiently (struct packet *packet, size_t amount)
{
if (! packet_fit (packet, amount))
@@ -184,6 +212,8 @@ packet_ensure_efficiently (struct packet *packet, size_t amount)
}
return 0;
}
+
+#endif /* Use extern inlines. */
struct pq
{
@@ -196,10 +226,14 @@ struct pq
the packet, or deallocated by calling pipe_dealloc_addr. */
struct packet *pq_queue (struct pq *pq, unsigned type, void *source);
+extern struct packet * pq_tail (struct pq *pq, unsigned type, void *source);
+
+#if defined(__USE_EXTERN_INLINES) || defined(PQ_DEFINE_EI)
+
/* Returns the tail of the packet queue PQ, which may mean pushing a new
packet if TYPE and SOURCE do not match the current tail, or this is the
first packet. */
-extern inline struct packet *
+PQ_EI struct packet *
pq_tail (struct pq *pq, unsigned type, void *source)
{
struct packet *tail = pq->tail;
@@ -209,16 +243,24 @@ pq_tail (struct pq *pq, unsigned type, void *source)
return tail;
}
+#endif /* Use extern inlines. */
+
/* Remove the first packet (if any) in PQ, deallocating any resources it
holds. True is returned if a packet was found, false otherwise. */
int pq_dequeue (struct pq *pq);
+extern struct packet * pq_head (struct pq *pq, unsigned type, void *source);
+
+extern struct packet * pq_next (struct pq *pq, unsigned type, void *source);
+
+#if defined(__USE_EXTERN_INLINES) || defined(PQ_DEFINE_EI)
+
/* Returns the next available packet in PQ, without removing it from the
- queue, or NULL if there is none, or the next packet isn't appropiate.
- A packet is inappropiate if SOURCE is non-NULL its source field doesn't
+ queue, or NULL if there is none, or the next packet isn't appropriate.
+ A packet is inappropriate if SOURCE is non-NULL its source field doesn't
match it, or TYPE is non-NULL and the packet's type field doesn't match
it. */
-extern inline struct packet *
+PQ_EI struct packet *
pq_head (struct pq *pq, unsigned type, void *source)
{
struct packet *head = pq->head;
@@ -232,7 +274,7 @@ pq_head (struct pq *pq, unsigned type, void *source)
}
/* The same as pq_head, but first discards the head of the queue. */
-extern inline struct packet *
+PQ_EI struct packet *
pq_next (struct pq *pq, unsigned type, void *source)
{
if (!pq->head)
@@ -241,6 +283,8 @@ pq_next (struct pq *pq, unsigned type, void *source)
return pq_head (pq, type, source);
}
+#endif /* Use extern inlines. */
+
/* Dequeues all packets in PQ. */
void pq_drain (struct pq *pq);