summaryrefslogtreecommitdiff
path: root/include/queue.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/queue.h')
-rw-r--r--include/queue.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/queue.h b/include/queue.h
new file mode 100644
index 0000000000..2c967ee4a8
--- /dev/null
+++ b/include/queue.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Queue data structure.
+ */
+
+#include "common.h"
+
+/* Generic queue container.
+ *
+ * head: next to dequeqe
+ * tail: next to enqueue
+ *
+ * Empty:
+ * head == tail
+ * Full:
+ * ((tail + 1) % buf_bytes) == head
+ */
+struct queue {
+ int head, tail;
+ int buf_bytes; /* size of buffer (in byte) */
+ int unit_bytes; /* size of unit (in byte) */
+ uint8_t *buf;
+};
+
+/* Reset the queue to empty state. */
+void queue_reset(struct queue *queue);
+
+/* Return TRUE if the queue is empty. */
+int queue_is_empty(const struct queue *q);
+
+/* Return TRUE if the queue has at least one unit space. */
+int queue_has_space(const struct queue *q, int unit_count);
+
+/* Add multiple units into queue. */
+void queue_add_units(struct queue *q, const void *src, int unit_count);
+
+/* Remove one unit from the begin of the queue. */
+int queue_remove_unit(struct queue *q, void *dest);