ipaccess \
profile \
fastbuf ff-binary ff-string ff-printf ff-utf8 \
- fb-file carefulio fb-mem fb-temp fb-mmap fb-limfd fb-buffer fb-grow fb-atomic fb-param \
+ fb-file carefulio fb-mem fb-temp fb-mmap fb-limfd fb-buffer fb-grow fb-pool fb-atomic fb-param \
str_ctype str_upper str_lower unicode-utf8 stkstring \
wildmatch wordsplit ctmatch patimatch patmatch regex \
prime primetable random timer randomkey \
$(o)/lib/ipaccess-test: $(o)/lib/ipaccess-test.o $(LIBUCW)
TESTS+=$(addprefix $(o)/lib/,regex.test unicode-utf8.test hash-test.test mempool.test stkstring.test \
- slists.test kmp-test.test bbuf.test getopt.test)
+ slists.test kmp-test.test bbuf.test getopt.test fb-pool.test)
$(o)/lib/regex.test: $(o)/lib/regex-t
$(o)/lib/unicode-utf8.test: $(o)/lib/unicode-utf8-t
$(o)/lib/kmp-test.test: $(o)/lib/kmp-test
$(o)/lib/bbuf.test: $(o)/lib/bbuf-t
$(o)/lib/getopt.test: $(o)/lib/getopt-t
+$(o)/lib/fb-pool.test: $(o)/lib/fb-pool-t
ifdef CONFIG_UCW_THREADS
TESTS+=$(addprefix $(o)/lib/,asio.test)
void fbgrow_reset(struct fastbuf *b); /* Reset stream and prepare for writing */
void fbgrow_rewind(struct fastbuf *b); /* Prepare for reading */
+/* FastO on memory pools */
+
+struct mempool;
+struct fbpool {
+ struct fastbuf fb;
+ struct mempool *mp;
+};
+
+void fbpool_init(struct fbpool *fb);
+void fbpool_start(struct fbpool *fb, struct mempool *mp, uns init_size);
+void *fbpool_end(struct fbpool *fb);
+
/* FastO with atomic writes for multi-threaded programs */
struct fb_atomic {
--- /dev/null
+/*
+ * UCW Library -- Fast Buffered I/O on Memory Pools
+ *
+ * (c) 2007 Pavel Charvat <pchar@ucw.cz>
+ *
+ * This software may be freely distributed and used according to the terms
+ * of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+#include "lib/mempool.h"
+#include "lib/fastbuf.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define FB_POOL(f) ((struct fbpool *)(f)->is_fastbuf)
+
+static void
+fbpool_spout(struct fastbuf *b)
+{
+ if (b->bptr >= b->bufend)
+ {
+ uns len = b->bufend - b->buffer;
+ b->buffer = mp_expand(FB_POOL(b)->mp);
+ b->bufend = b->buffer + mp_avail(FB_POOL(b)->mp);
+ b->bstop = b->buffer;
+ b->bptr = b->buffer + len;
+ }
+}
+
+void
+fbpool_start(struct fbpool *b, struct mempool *mp, uns init_size)
+{
+ b->mp = mp;
+ b->fb.buffer = b->fb.bstop = b->fb.bptr = mp_start(mp, init_size);
+ b->fb.bufend = b->fb.buffer + mp_avail(mp);
+}
+
+void *
+fbpool_end(struct fbpool *b)
+{
+ return mp_end(b->mp, b->fb.bptr);
+}
+
+void
+fbpool_init(struct fbpool *b)
+{
+ bzero(b, sizeof(*b));
+ b->fb.name = "<fbpool>";
+ b->fb.spout = fbpool_spout;
+ b->fb.can_overwrite_buffer = 1;
+}
+
+#ifdef TEST
+
+int main(void)
+{
+ struct mempool *mp;
+ struct fbpool fb;
+ byte *p;
+ uns l;
+
+ mp = mp_new(64);
+ fbpool_init(&fb);
+ fbpool_start(&fb, mp, 16);
+ for (uns i = 0; i < 1024; i++)
+ bprintf(&fb.fb, "<hello>");
+ p = fbpool_end(&fb);
+ l = mp_size(mp, p);
+ if (l != 1024 * 7)
+ ASSERT(0);
+ for (uns i = 0; i < 1024; i++)
+ if (memcmp(p + i * 7, "<hello>", 7))
+ ASSERT(0);
+ mp_delete(mp);
+
+ return 0;
+}
+
+#endif