membuf: Support a flag for being full

At present the membuf implementation wastes a slot in the fifo so it can
detect the difference between a full and an empty buffer.

Add the option of supporting a boolean flag, if desired. For now it is
off.

The code-size penalty is non-zero, but the space penalty is small and
could be reduced on 64-bit machines by using a u32 offset for head and
tail.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2024-10-17 21:00:27 -06:00
parent 372ad68148
commit b5b151cfb5
3 changed files with 65 additions and 15 deletions

View File

@@ -23,6 +23,11 @@ static void membuf_zero(struct membuf *mb)
static int membuf_check(struct unit_test_state *uts, struct membuf *mb,
int value)
{
/* says it is full, but can't be */
#if MEMBUF_FULL
ut_assert(!(mb->full && mb->head != mb->tail));
#endif
/* head is out of range */
ut_assert(!(mb->head < mb->start || mb->head >= mb->end));
@@ -47,7 +52,7 @@ static int lib_test_membuf_one(struct unit_test_state *uts)
in[i + TEST_SIZE] = in[i];
}
test_size = TEST_SIZE;
test_size = TEST_SIZE + MEMBUF_FULL;
for (i = 1; i < TEST_COUNT; i++) {
membuf_zero(&mb);
@@ -92,7 +97,7 @@ static int lib_test_membuf_random(struct unit_test_state *uts)
in[i + TEST_SIZE] = in[i];
}
test_size = TEST_SIZE;
test_size = TEST_SIZE + MEMBUF_FULL;
inptr = in;
outptr = in;
@@ -145,7 +150,7 @@ static int lib_test_membuf_extend(struct unit_test_state *uts)
in[i + TEST_SIZE] = in[i];
}
test_size = TEST_SIZE - 1;
test_size = TEST_SIZE - 1 + MEMBUF_FULL;
for (cur = 0; cur <= test_size; cur++) {
ut_assertok(membuf_new(&mb, TEST_SIZE));