Commit 4d29a96a authored by Niels Möller's avatar Niels Möller
Browse files

* src/queue.c (lsh_queue_peek_head): New function.

(lsh_queue_peek_tail): -"-
(object_queue_peek_head): -"-
(object_queue_peek_tail): -"-
(object_queue_get_contents): Cast here, rather than in all calling
functions.

Rev: src/queue.c:1.6
Rev: src/queue.h:1.5
parent b4732d7b
/* queue.c
/* queue.c
*
* $Id$
*
......@@ -148,6 +148,16 @@ struct lsh_queue_node *lsh_queue_remove_tail(struct lsh_queue *q)
return n;
}
struct lsh_queue_node *lsh_queue_peek_head(struct lsh_queue *q)
{
return EMPTYP(q) ? NULL : q->head;
}
struct lsh_queue_node *lsh_queue_peek_tail(struct lsh_queue *q)
{
return EMPTYP(q) ? NULL : q->tailprev;
}
static struct object_queue_node *
make_object_queue_node(struct lsh_object *o)
{
......@@ -170,24 +180,40 @@ void object_queue_add_tail(struct object_queue *q, struct lsh_object *o)
}
static struct lsh_object *
object_queue_get_contents(struct object_queue_node *n)
object_queue_get_contents(struct lsh_queue_node *l)
{
struct object_queue_node *n = (struct object_queue_node *) l;
struct lsh_object *res = n->o;
lsh_space_free(n);
return res;
}
static struct lsh_object *
object_queue_peek(struct lsh_queue_node *n)
{
return ( (struct object_queue_node *) n)->o;
}
struct lsh_object *object_queue_remove_head(struct object_queue *q)
{
return object_queue_get_contents((struct object_queue_node *)
lsh_queue_remove_head(&q->q));
return object_queue_get_contents(lsh_queue_remove_head(&q->q));
}
struct lsh_object *object_queue_remove_tail(struct object_queue *q)
{
return object_queue_get_contents((struct object_queue_node *)
lsh_queue_remove_tail(&q->q));
return object_queue_get_contents(lsh_queue_remove_tail(&q->q));
}
struct lsh_object *object_queue_peek_head(struct object_queue *q)
{
return EMPTYP(&q->q) ? NULL : object_queue_peek(q->q.head);
}
struct lsh_object *object_queue_peek_tail(struct object_queue *q)
{
return EMPTYP(&q->q) ? NULL : object_queue_peek(q->q.tailprev);
}
/* For gc */
......
......@@ -66,6 +66,9 @@ void lsh_queue_remove(struct lsh_queue_node *n);
struct lsh_queue_node *lsh_queue_remove_head(struct lsh_queue *q);
struct lsh_queue_node *lsh_queue_remove_tail(struct lsh_queue *q);
struct lsh_queue_node *lsh_queue_peek_head(struct lsh_queue *q);
struct lsh_queue_node *lsh_queue_peek_tail(struct lsh_queue *q);
#define GABA_DECLARE
#include "queue.h.x"
#undef GABA_DECLARE
......@@ -93,6 +96,9 @@ void object_queue_add_tail(struct object_queue *q, struct lsh_object *o);
struct lsh_object *object_queue_remove_head(struct object_queue *q);
struct lsh_object *object_queue_remove_tail(struct object_queue *q);
struct lsh_object *object_queue_peek_head(struct object_queue *q);
struct lsh_object *object_queue_peek_tail(struct object_queue *q);
#define FOR_OBJECT_QUEUE(oq, n) \
struct lsh_queue_node *n##_this, *n##_next; \
struct lsh_object *n; \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment