return buf->size == 0;
}
+void ncbmb_init(struct ncbmbuf *buf, ncb_sz_t head);
struct ncbmbuf ncbmb_make(char *area, ncb_sz_t size, ncb_sz_t head);
-<<<<<<< HEAD
-/* Returns the usable size of <buf> for data storage. This is the size of the
- * allocated buffer without the bitmap space.
- */
-=======
+/* Returns start of allocated buffer area. */
static inline char *ncbmb_orig(const struct ncbmbuf *buf)
{
return buf->area;
}
+/* Returns current head pointer into buffer area. */
static inline char *ncbmb_head(const struct ncbmbuf *buf)
{
return buf->area + buf->head;
}
+/* Returns the first byte after the allocated buffer area. */
static inline char *ncbmb_wrap(const struct ncbmbuf *buf)
{
return buf->area + buf->size;
}
->>>>>>> 932ad4878 (MINOR: ncbmbuf: support wrapping during add operation)
+/* Returns the usable size of <buf> for data storage. This is the size of the
+ * allocated buffer without the bitmap space.
+ */
static inline ncb_sz_t ncbmb_size(const struct ncbmbuf *buf)
{
if (ncbmb_is_null(buf))
return buf->size;
}
+int ncbmb_is_empty(const struct ncbmbuf *buf);
+
ncb_sz_t ncbmb_data(const struct ncbmbuf *buf, ncb_sz_t offset);
enum ncb_ret ncbmb_add(struct ncbmbuf *buf, ncb_sz_t off,
/* ******** public API ******** */
+/* Initialize or reset <buf> by clearing all data. Its size is untouched.
+ * Buffer is positioned to <head> offset. Use 0 to realign it. <buf> must not
+ * be NCBUF_NULL.
+ */
+void ncbmb_init(struct ncbmbuf *buf, ncb_sz_t head)
+{
+ BUG_ON_HOT(ncbmb_is_null(buf));
+
+ BUG_ON_HOT(head >= buf->size);
+ buf->head = head;
+ memset(buf->bitmap, 0, buf->bitmap_sz);
+}
+
/* Construct a ncbmbuf with all its parameters. */
struct ncbmbuf ncbmb_make(char *area, ncb_sz_t size, ncb_sz_t head)
{
int ncbmb_is_empty(const struct ncbmbuf *buf)
{
- /* TODO */
- return 0;
+ size_t i = 0;
+
+ if (ncbmb_is_null(buf))
+ return 1;
+
+ for (i = 0; i < buf->bitmap_sz; ++i) {
+ if (buf->bitmap[i])
+ return 0;
+ }
+
+ return 1;
}
int ncbmb_is_full(const struct ncbmbuf *buf)