diff options
author | Vic Yang <victoryang@chromium.org> | 2013-06-10 13:44:12 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-06-10 01:48:44 -0700 |
commit | a9541220dc92ba70d9828c6000c89dc8287bc7a1 (patch) | |
tree | 33520630f207cbe442f341d0c1f47a0cfbab9682 /common/queue.c | |
parent | 8bed9853d7722676e49f28e36c170166dc36c8c5 (diff) | |
download | chrome-ec-a9541220dc92ba70d9828c6000c89dc8287bc7a1.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
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>
Diffstat (limited to 'common/queue.c')
-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) |