Commit b3cc8ae7 authored by Rusty Russell's avatar Rusty Russell

membuf: add membuf_added and membuf_unadd APIs.

Clean up some whitespace while we're there too.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 7d1f0c73
......@@ -133,6 +133,20 @@ static inline void *membuf_space_(struct membuf *mb, size_t elemsize)
return mb->elems + mb->end * elemsize;
}
/**
* membuf_added - declare that we've added this many elements.
* @mb: the MEMBUF() declared membuf.
* @n: the number of elements we added (must be < membuf_num_space()).
*/
#define membuf_added(mb, num) \
membuf_added_(tcon_unwrap(mb), (num))
static inline void membuf_added_(struct membuf *mb, size_t num)
{
assert(num <= membuf_num_space_(mb));
mb->end += num;
}
/**
* membuf_prepare_space - internal routine to make sure we've got space.
* @mb: the MEMBUF() declared membuf.
......@@ -181,12 +195,25 @@ static inline void *membuf_add_(struct membuf *mb, size_t num, size_t elemsize)
oldend = membuf_space_(mb, elemsize);
/* We assume expandfn succeeded. */
assert(num <= membuf_num_space_(mb));
mb->end += num;
membuf_added_(mb, num);
return oldend;
}
/**
* membuf_unadd - remove this many added elements.
* @mb: the MEMBUF() declared membuf.
* @n: the number of elements we want to "unadd" (must be < membuf_num_elems()).
*/
#define membuf_unadd(mb, num) \
membuf_unadd_(tcon_unwrap(mb), (num))
static inline void membuf_unadd_(struct membuf *mb, size_t num)
{
assert(num <= membuf_num_elems_(mb));
mb->end -= num;
}
/**
* membuf_cleanup - reset membuf, return elems array for freeing.
* @mb: the MEMBUF() declared membuf.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment