return btrp->rhead - btrp->whead;
}
+/**
+ * Obtain the current write head.
+ *
+ * \param btrp The buffer pool.
+ * \param result The write head is returned here.
+ *
+ * \return The maximal amount of bytes that may be written to the returned
+ * buffer.
+ */
size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result)
{
if (result)
return btr_pool_available(btrp);
}
-void btr_pool_allocate(struct btr_pool *btrp, size_t size)
+/**
+ * Mark a part of the buffer pool area as allocated.
+ *
+ * \param btrp The buffer pool.
+ * \param size The amount of bytes to be allocated.
+ *
+ * This is usually called after the caller wrote to the buffer obtained by
+ * btr_pool_get_buffer().
+ */
+static void btr_pool_allocate(struct btr_pool *btrp, size_t size)
{
char *end;
add_btrb_to_children(btrb, btrn, 0);
}
+/**
+ * Feed data to child nodes of the buffer tree.
+ *
+ * \param btrp The buffer pool.
+ *
+ */
void btr_add_output_pool(struct btr_pool *btrp, size_t size,
struct btr_node *btrn)
{
add_btrb_to_children(btrb, btrn, 0);
}
+/**
+ * Copy data to write head of a buffer pool and feed it to all children nodes.
+ *
+ * \param src The source buffer.
+ * \param n The size of the source buffer in bytes.
+ * \param btrp The destination buffer pool.
+ * \param btrn Add the data as output of this node.
+ *
+ * This is expensive. The caller must make sure the data fits into the buffer
+ * pool area.
+ */
void btr_copy(const void *src, size_t n, struct btr_pool *btrp,
struct btr_node *btrn)
{
struct btr_pool *btr_pool_new(const char *name, size_t area_size);
void btr_pool_free(struct btr_pool *btrp);
size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result);
-void btr_pool_allocate(struct btr_pool *btrp, size_t size);
void btr_add_output_pool(struct btr_pool *btrp, size_t size,
struct btr_node *btrn);
size_t btr_pool_unused(struct btr_pool *btrp);