From 2c9aa505622e524dd4fa031981da1b432c8fadef Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Tue, 29 May 2007 10:50:31 +0200 Subject: [PATCH] first experiments with parametrized fastbufs --- lib/Makefile | 2 +- lib/fastbuf.h | 16 ++++++++++ lib/fb-file.c | 1 + lib/fb-param.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 lib/fb-param.c diff --git a/lib/Makefile b/lib/Makefile index 01692986..c23ac8c5 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,7 @@ LIBUCW_MODS= \ 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-file carefulio fb-mem fb-temp fb-mmap fb-limfd fb-buffer fb-grow fb-atomic fb-param \ str_ctype str_upper str_lower unicode-utf8 stkstring \ wildmatch wordsplit ctmatch patimatch patmatch regex \ prime primetable random timer randomkey \ diff --git a/lib/fastbuf.h b/lib/fastbuf.h index ee0a7732..e7d441b5 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -102,6 +102,22 @@ struct fastbuf *fbdir_open_try(byte *name, uns mode, struct asio_queue *io_queue struct fastbuf *fbdir_open_fd(int fd, struct asio_queue *io_queue); struct fastbuf *fbdir_open_tmp(struct asio_queue *io_queue); +/* FastIO on files with run-time parametrization */ + +struct fb_params { + // FIXME + uns odirect; + uns buffer_size; +}; + +struct cf_section; +extern struct cf_section fbpar_cf; + +struct fastbuf *fbpar_open(byte *name, int mode, struct fb_params *params); +struct fastbuf *fbpar_open_try(byte *name, int mode, struct fb_params *params); +struct fastbuf *fbpar_open_fd(int fd, struct fb_params *params); +struct fastbuf *fbpar_open_tmp(struct fb_params *params); + /* FastI on file descriptors with limit */ struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit); diff --git a/lib/fb-file.c b/lib/fb-file.c index a7290cbf..0d1cc96c 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -98,6 +98,7 @@ bfdopen_internal(int fd, uns buflen, byte *name) struct fb_file *F = xmalloc(sizeof(struct fb_file) + buflen + namelen); struct fastbuf *f = &F->fb; + ASSERT(buflen); bzero(F, sizeof(*F)); f->buffer = (byte *)(F+1); f->bptr = f->bstop = f->buffer; diff --git a/lib/fb-param.c b/lib/fb-param.c new file mode 100644 index 00000000..56f9b3f9 --- /dev/null +++ b/lib/fb-param.c @@ -0,0 +1,81 @@ +/* + * UCW Library -- FastIO on files with run-time parametrization + * + * (c) 2007 Pavel Charvat + * + * 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/conf.h" +#include "lib/fastbuf.h" + +static struct fb_params fbpar_defaults = { + .buffer_size = 65536, +}; + +struct cf_section fbpar_cf = { +# define F(x) PTR_TO(struct fb_params, x) + CF_TYPE(struct fb_params), + CF_ITEMS { + // FIXME + CF_UNS("DirectIO", F(odirect)), + CF_UNS("BufSize", F(buffer_size)), + CF_END + } +# undef F +}; + +static struct cf_section fbpar_global_cf = { + CF_ITEMS { + CF_SECTION("Defaults", &fbpar_defaults, &fbpar_cf), + CF_END + } +}; + +static void CONSTRUCTOR +fbpar_global_init(void) +{ + cf_declare_section("FBParam", &fbpar_global_cf, 0); +} + +struct fastbuf * +fbpar_open(byte *name, int mode, struct fb_params *params) +{ + params = params ? : &fbpar_defaults; + if (!params->odirect) + return bopen(name, mode, params->buffer_size); + else + return fbdir_open(name, mode, NULL); +} + +struct fastbuf * +fbpar_open_try(byte *name, int mode, struct fb_params *params) +{ + params = params ? : &fbpar_defaults; + if (!params->odirect) + return bopen_try(name, mode, params->buffer_size); + else + return fbdir_open_try(name, mode, NULL); +} + +struct fastbuf * +fbpar_open_fd(int fd, struct fb_params *params) +{ + params = params ? : &fbpar_defaults; + if (!params->odirect) + return bfdopen(fd, params->buffer_size); + else + return fbdir_open_fd(fd, NULL); +} + +struct fastbuf * +fbpar_open_tmp(struct fb_params *params) +{ + params = params ? : &fbpar_defaults; + if (!params->odirect) + return bopen_tmp(params->buffer_size); + else + return fbdir_open_tmp(NULL); +} -- 2.39.2