Bug fix of queue empty slot calculation

Current implementation of queue_has_space doesn't handle the case where
queue tail has wrapped around the end. This CL fixes the bug.

BUG=None
TEST=Pass the test in the following CL.
BRANCH=link

Change-Id: I774f388081af50f0e930a6cbc3a723da1c8283b0
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/58031
Reviewed-by: Yung-Chieh Lo <yjlou@chromium.org>
This commit is contained in:
Vic Yang
2013-06-09 18:55:16 +08:00
committed by ChromeBot
parent 149a8457aa
commit 8bed9853d7

View File

@@ -19,8 +19,12 @@ int queue_is_empty(const struct queue *q)
int queue_has_space(const struct queue *q, int unit_count)
{
return (q->tail + unit_count * q->unit_bytes) <=
(q->head + q->buf_bytes - q->unit_bytes);
if (q->tail >= q->head)
return (q->tail + unit_count * q->unit_bytes) <=
(q->head + q->buf_bytes - q->unit_bytes);
else
return (q->tail + unit_count * q->unit_bytes) <=
(q->head - q->unit_bytes);
}
void queue_add_units(struct queue *q, const void *src, int unit_count)