X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffastbuf.h;h=922798ff183515a3d102191c6e614569373088e1;hb=b4d79987a979bcbf749294c706fdc8c4ae8f9304;hp=2d1c1eb3b5fc641eb6e8ba0b300ec8447e8a3cbe;hpb=9dc6f017d0b8c992d2df15a51cf96fc431260df3;p=libucw.git diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 2d1c1eb3..922798ff 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -19,7 +19,6 @@ #include #include "lib/unaligned.h" -#include "lib/bbuf.h" /* * Generic buffered I/O. You supply hooks to be called for low-level operations @@ -120,8 +119,23 @@ void fbgrow_rewind(struct fastbuf *b); /* Prepare for reading */ /* FastO with atomic writes for multi-threaded programs */ -struct fastbuf *fbatomic_create(byte *name, struct fastbuf *master, uns bufsize, int record_len); -void fbatomic_checkpoint(struct fastbuf *b); +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 */ @@ -327,7 +341,8 @@ int bgets_nodie(struct fastbuf *f, byte *b, uns l); byte *bgets0(struct fastbuf *f, byte *b, uns l); struct mempool; -uns bgets_bb(struct fastbuf *f, bb_t *b, uns limit); +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 {