diff options
author | Vic Yang <victoryang@chromium.org> | 2013-06-10 13:44:12 +0800 |
---|---|---|
committer | Yung-chieh Lo <yjlou@chromium.org> | 2013-12-10 01:04:16 +0000 |
commit | faa02fb3870577acbc508f12996612ed9ea0cdbe (patch) | |
tree | 4024a46e7d846c82e531fd532d4e5709a57d0269 | |
parent | c02995c44324502f6fa5c38b74668734922d4cfa (diff) | |
download | chrome-ec-faa02fb3870577acbc508f12996612ed9ea0cdbe.tar.gz |
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 <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/58058
Reviewed-by: Yung-Chieh Lo <yjlou@chromium.org>
(cherry picked from commit a9541220dc92ba70d9828c6000c89dc8287bc7a1)
Change-Id: I718daeb1b91c8df219006557ec77e64801a35e3a
Reviewed-on: https://chromium-review.googlesource.com/179404
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Yung-chieh Lo <yjlou@chromium.org>
Tested-by: Yung-chieh Lo <yjlou@chromium.org>
-rw-r--r-- | common/queue.c | 4 |
1 files 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) |