]> mj.ucw.cz Git - libucw.git/commitdiff
Fastbuf: fbmulti_remove
authorJan 'Moskyt' Matejka <mq@ucw.cz>
Mon, 16 Jul 2012 09:27:28 +0000 (11:27 +0200)
committerJan 'Moskyt' Matejka <mq@ucw.cz>
Thu, 19 Jul 2012 13:25:28 +0000 (15:25 +0200)
ucw/fastbuf.h
ucw/fb-multi.c

index 5c3ad1291c707ce88ee94f0c46c84b7ec8cc04a9..40b60dcac5e2075a601e3d755f95a42a3ac06b9f 100644 (file)
@@ -509,11 +509,16 @@ static inline void fbatomic_commit(struct fastbuf *b)
  * fbmulti is seeked to the beginning, flushed and ready to read the whole buffer.
  *
  * For performance reasons, use @fbmulti_flatten() only once, just before reading.
+ *
+ * If you want to remove a fastbuf from the chain, just call @fbmulti_remove
+ * where the second parameter is a pointer to the removed fastbuf. If you pass
+ * NULL, all the underlying fastbufs are removed.
  ***/
 
 struct fastbuf *fbmulti_create(uns bufsize, ...) SENTINEL_CHECK;
 void fbmulti_append(struct fastbuf *f, struct fastbuf *fa, int allow_close);
 void fbmulti_flatten(struct fastbuf *f);
+void fbmulti_remove(struct fastbuf *f, struct fastbuf *fb);
 
 
 /*** === Configuring stream parameters [[bconfig]] ***/
index 0bf6d9e4a0cdacf92ee3874a07313b07e1341634..8071aa0cbed0e5cf70d6499066a16acb29b56580 100644 (file)
@@ -154,7 +154,7 @@ fbmulti_update_capability(struct fastbuf *f)
 
   CLIST_FOR_EACH(struct subbuf *, n, *(FB_MULTI(f)->subbufs))
     {
-      ASSERT(n->fb->refill)
+      ASSERT(n->fb->refill);
 
       if (!n->fb->seek)
        f->seek = NULL;
@@ -210,6 +210,29 @@ fbmulti_append(struct fastbuf *f, struct fastbuf *fb, int allow_close)
   sb->fb = fb;
   sb->allow_close = allow_close;
   clist_add_tail(FB_MULTI(f)->subbufs, &(sb->n));
+  fbmulti_update_capability(f);
+}
+
+void
+fbmulti_remove(struct fastbuf *f, struct fastbuf *fb)
+{
+  if (fb)
+    {
+      CLIST_FOR_EACH(struct subbuf *, n, *(FB_MULTI(f)->subbufs))
+       if (fb == n->fb)
+         {
+           // TODO: fix seek positions
+           clist_remove(&(n->n));
+           fbmulti_update_capability(f);
+           return;
+         }
+
+      die("Given fastbuf %p not in given fbmulti %p.", fb, f);
+    }
+  else
+    clist_init(FB_MULTI(f)->subbufs);
+
+  fbmulti_update_capability(f);
 }
 
 static void fbmulti_flatten_internal(struct fastbuf *f, clist *c, int allow_close)