blob: 2c967ee4a846fb4bb52394ec6475ae39f844cdb2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
|