]> mj.ucw.cz Git - libucw.git/commitdiff
first experiments with parametrized fastbufs
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 29 May 2007 08:50:31 +0000 (10:50 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 29 May 2007 08:50:31 +0000 (10:50 +0200)
lib/Makefile
lib/fastbuf.h
lib/fb-file.c
lib/fb-param.c [new file with mode: 0644]

index 01692986cc408a68e4dbc699041f7d13fd1de1bb..c23ac8c576850cda75d49f51a718735c1ec3d892 100644 (file)
@@ -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 \
index ee0a77329c6fd693959473e374eb6b313b9184cd..e7d441b5fa81ae01d8496a4365383ee4abeeaaaf 100644 (file)
@@ -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);
index a7290cbf8688f9de261a38c4e50dbb9584eee91e..0d1cc96cbd8cca573086d4302f76355398271142 100644 (file)
@@ -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 (file)
index 0000000..56f9b3f
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ *     UCW Library -- FastIO on files with run-time parametrization
+ *
+ *     (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/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);
+}