summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/queue.c23
-rw-r--r--include/queue.h19
2 files changed, 31 insertions, 11 deletions
diff --git a/common/queue.c b/common/queue.c
index 6e5e9e65ad..e289584a85 100644
--- a/common/queue.c
+++ b/common/queue.c
@@ -42,7 +42,7 @@ size_t queue_space(struct queue const *q)
return q->buffer_units - queue_count(q);
}
-size_t queue_add_unit(struct queue const *q, void const *src)
+size_t queue_add_unit(struct queue const *q, const void *src)
{
size_t tail = q->state->tail & (q->buffer_units - 1);
@@ -61,16 +61,16 @@ size_t queue_add_unit(struct queue const *q, void const *src)
return 1;
}
-size_t queue_add_units(struct queue const *q, void const *src, size_t count)
+size_t queue_add_units(struct queue const *q, const void *src, size_t count)
{
return queue_add_memcpy(q, src, count, memcpy);
}
size_t queue_add_memcpy(struct queue const *q,
- void const *src,
+ const void *src,
size_t count,
void *(*memcpy)(void *dest,
- void const *src,
+ const void *src,
size_t n))
{
size_t transfer = MIN(count, queue_space(q));
@@ -98,7 +98,7 @@ static void queue_read_safe(struct queue const *q,
size_t head,
size_t transfer,
void *(*memcpy)(void *dest,
- void const *src,
+ const void *src,
size_t n))
{
size_t first = MIN(transfer, q->buffer_units - head);
@@ -141,7 +141,7 @@ size_t queue_remove_memcpy(struct queue const *q,
void *dest,
size_t count,
void *(*memcpy)(void *dest,
- void const *src,
+ const void *src,
size_t n))
{
size_t transfer = MIN(count, queue_count(q));
@@ -161,6 +161,17 @@ size_t queue_peek_units(struct queue const *q,
size_t i,
size_t count)
{
+ return queue_peek_memcpy(q, dest, i, count, memcpy);
+}
+
+size_t queue_peek_memcpy(struct queue const *q,
+ void *dest,
+ size_t i,
+ size_t count,
+ void *(*memcpy)(void *dest,
+ const void *src,
+ size_t n))
+{
size_t available = queue_count(q);
size_t transfer = MIN(count, available - i);
diff --git a/include/queue.h b/include/queue.h
index a893b58194..d415b63a68 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -106,17 +106,17 @@ size_t queue_count(struct queue const *q);
size_t queue_space(struct queue const *q);
/* Add one unit to queue. */
-size_t queue_add_unit(struct queue const *q, void const *src);
+size_t queue_add_unit(struct queue const *q, const void *src);
/* Add multiple units to queue. */
-size_t queue_add_units(struct queue const *q, void const *src, size_t count);
+size_t queue_add_units(struct queue const *q, const void *src, size_t count);
/* Add multiple units to queue using supplied memcpy. */
size_t queue_add_memcpy(struct queue const *q,
- void const *src,
+ const void *src,
size_t count,
void *(*memcpy)(void *dest,
- void const *src,
+ const void *src,
size_t n));
/* Remove one unit from the begin of the queue. */
@@ -130,7 +130,7 @@ size_t queue_remove_memcpy(struct queue const *q,
void *dest,
size_t count,
void *(*memcpy)(void *dest,
- void const *src,
+ const void *src,
size_t n));
/* Peek (return but don't remove) the count elements starting with the i'th. */
@@ -139,6 +139,15 @@ size_t queue_peek_units(struct queue const *q,
size_t i,
size_t count);
+/* Peek (return but don't remove) the count elements starting with the i'th. */
+size_t queue_peek_memcpy(struct queue const *q,
+ void *dest,
+ size_t i,
+ size_t count,
+ void *(*memcpy)(void *dest,
+ const void *src,
+ size_t n));
+
/*
* These macros will statically select the queue functions based on the number
* of units that are to be added or removed if they can. The single unit add