From faa02fb3870577acbc508f12996612ed9ea0cdbe Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Mon, 10 Jun 2013 13:44:12 +0800 Subject: Only waste 1 byte in queue buffer For simplicity of the code, we don't allow (head == tail) when the queue is full. But currently we are wasting the size of a single unit, while we can actually just waste 1 byte. Let's fix this. BUG=None TEST=Pass the unit test. BRANCH=None Original-Change-Id: Id09c20a9345ebb3ec0cad659afe36e25b422e688 Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/58058 Reviewed-by: Yung-Chieh Lo (cherry picked from commit a9541220dc92ba70d9828c6000c89dc8287bc7a1) Change-Id: I718daeb1b91c8df219006557ec77e64801a35e3a Reviewed-on: https://chromium-review.googlesource.com/179404 Reviewed-by: Randall Spangler Commit-Queue: Yung-chieh Lo Tested-by: Yung-chieh Lo --- common/queue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/queue.c b/common/queue.c index 46ea749979..5386cc7c2f 100644 --- a/common/queue.c +++ b/common/queue.c @@ -21,10 +21,10 @@ int queue_has_space(const struct queue *q, int unit_count) { if (q->tail >= q->head) return (q->tail + unit_count * q->unit_bytes) <= - (q->head + q->buf_bytes - q->unit_bytes); + (q->head + q->buf_bytes - 1); else return (q->tail + unit_count * q->unit_bytes) <= - (q->head - q->unit_bytes); + (q->head - 1); } void queue_add_units(struct queue *q, const void *src, int unit_count) -- cgit v1.2.1