]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.h
Use big_alloc().
[libucw.git] / lib / fastbuf.h
index af6787aeaf5cc29a2f3e28856c0aa0cf18d85fab..922798ff183515a3d102191c6e614569373088e1 100644 (file)
@@ -16,6 +16,7 @@
 #endif
 
 #include <string.h>
+#include <alloca.h>
 
 #include "lib/unaligned.h"
 
@@ -116,6 +117,26 @@ struct fastbuf *fbgrow_create(unsigned basic_size);
 void fbgrow_reset(struct fastbuf *b);                  /* Reset stream and prepare for writing */
 void fbgrow_rewind(struct fastbuf *b);                 /* Prepare for reading */
 
+/* FastO with atomic writes for multi-threaded programs */
+
+struct fb_atomic {
+  struct fastbuf fb;
+  struct fb_atomic_file *af;
+  byte *expected_max_bptr;
+  uns slack_size;
+};
+#define FB_ATOMIC(f) ((struct fb_atomic *)(f)->is_fastbuf)
+
+struct fastbuf *fbatomic_open(byte *name, struct fastbuf *master, uns bufsize, int record_len);
+void fbatomic_internal_write(struct fastbuf *b);
+
+static inline void
+fbatomic_commit(struct fastbuf *b)
+{
+  if (b->bptr >= ((struct fb_atomic *)b)->expected_max_bptr)
+    fbatomic_internal_write(b);
+}
+
 /* Configuring stream parameters */
 
 int bconfig(struct fastbuf *f, uns type, int data);
@@ -319,6 +340,20 @@ byte *bgets(struct fastbuf *f, byte *b, uns l);    /* Non-std */
 int bgets_nodie(struct fastbuf *f, byte *b, uns l);
 byte *bgets0(struct fastbuf *f, byte *b, uns l);
 
+struct mempool;
+struct bb_t;
+uns bgets_bb(struct fastbuf *f, struct bb_t *b, uns limit);
+byte *bgets_mp(struct fastbuf *f, struct mempool *mp);
+
+struct bgets_stk_struct {
+  struct fastbuf *f;
+  byte *old_buf, *cur_buf, *src;
+  uns old_len, cur_len, src_len;
+};
+void bgets_stk_init(struct bgets_stk_struct *s);
+void bgets_stk_step(struct bgets_stk_struct *s);
+#define bgets_stk(fb) ({ struct bgets_stk_struct _s; _s.f = (fb); for (bgets_stk_init(&_s); _s.cur_len; _s.cur_buf = alloca(_s.cur_len), bgets_stk_step(&_s)); _s.cur_buf; })
+
 static inline void
 bputs(struct fastbuf *f, byte *b)
 {