]> mj.ucw.cz Git - libucw.git/commitdiff
Fastbufs are not tied to resources automatically any longer
authorMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 12:46:26 +0000 (14:46 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 12:46:26 +0000 (14:46 +0200)
Explicit tying by fb_tie() should be used instead.

ucw/doc/fastbuf.txt
ucw/fastbuf.c
ucw/fastbuf.h
ucw/fb-atomic.c
ucw/fb-direct.c
ucw/fb-file.c
ucw/fb-grow.c
ucw/fb-limfd.c
ucw/fb-mem.c
ucw/fb-mmap.c
ucw/fb-socket.c

index 86ab55d923dba0b55026c31489b4e050d4e9dfc9..47109906c9d7bf739c97634334f695dc95bc316f 100644 (file)
@@ -18,11 +18,10 @@ inbetween and remember that the file position reported by @btell() points after
 the flushed buffer, which is not necessarily the same as after the data you've
 really read.
 
-Most fastbuf back-ends also participate in the libucw resource management system.
-If you have a resource pool active, newly created fastbufs are automatically tied
-to resources in the pool, so when the pool gets cleaned up, the fastbufs are
-freed, too. The bclose() function is still available and it removes the tie
-as needed.
+Fastbufs can also participate in the libucw resource management system.
+You can tie a fastbuf to a resource in the current resource pool by @fb_tie().
+When the pool gets cleaned up, the fastbuf is automatically closed. If you call
+@bclose() explicitly, the resource is removed, too.
 
 .Back-ends:
 - <<fbparam,Files (parametrized)>>
index 4068aab89adef2e30868530da34ea70686d5e1b5..7bec4bfd4b08b8d9a20b53f249cd2fbb8d700f03 100644 (file)
@@ -23,11 +23,7 @@ void bclose(struct fastbuf *f)
   if (f)
     {
       bflush(f);
-      if (f->res)
-       {
-         res_drop(f->res);
-         f->res = NULL;
-       }
+      res_detach(f->res);
       DBG("FB: closing", f);
       if (f->close)
        f->close(f); /* Should always free all internal resources, even if it throws an exception */
index f418f66798ca4df430753e6288cd98cd7f4b53b4..990375242953d087a36062a8fbbb13bc4d0ac654 100644 (file)
@@ -144,8 +144,6 @@ struct fastbuf {
   struct resource *res;                                /* The fastbuf can be tied to a resource pool */
 };
 
-struct fastbuf *fb_tie(struct fastbuf *b);     /* Tie fastbuf to a resource if there is an active pool */
-
 /**
  * Fastbuf flags
  */
@@ -154,6 +152,9 @@ enum fb_flags {
   FB_DIE_ON_EOF = 0x2,                         /* Most of read operations throw "fb.eof" on EOF */
 };
 
+/** Tie a fastbuf to a resource in the current resource pool. Returns the pointer to the same fastbuf. **/
+struct fastbuf *fb_tie(struct fastbuf *b);
+
 /***
  * === Fastbuf on files [[fbparam]]
  *
index fca0dfb6582ed997653bed9703e9a47cae45be61..1dce8f08e1ab10a6add345018cb4a5616486a4ac 100644 (file)
@@ -133,7 +133,7 @@ fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_
   f->name = af->name;
   f->spout = fbatomic_spout;
   f->close = fbatomic_close;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
index ccdb851b1f492211edd069ee7400cd571e9ebea3..eb1144cae6ec321dcdb84400c5b02564d04db813 100644 (file)
@@ -308,7 +308,7 @@ fbdir_open_fd_internal(int fd, const char *name, struct asio_queue *q, uns buffe
   f->close = fbdir_close;
   f->config = fbdir_config;
   f->can_overwrite_buffer = 2;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
index cc5cf22cba1aa951290339c4205326d482589612..a7af6108742fcd4f7326bf1bc17b4f58384dbaaf 100644 (file)
@@ -238,7 +238,7 @@ bfdopen_internal(int fd, const char *name, uns buflen)
   f->close = bfd_close;
   f->config = bfd_config;
   f->can_overwrite_buffer = 2;
-  return fb_tie(f);
+  return f;
 }
 
 void
index ab80be0b0c85569234393d33c1d010629db682d2..803e411e651b7659eeb5afd4d6ab3e3247e1e8f8 100644 (file)
@@ -92,7 +92,7 @@ struct fastbuf *fbgrow_create_mp(struct mempool *mp, unsigned basic_size)
   b->spout = fbgrow_spout;
   b->seek = fbgrow_seek;
   b->can_overwrite_buffer = 1;
-  return fb_tie(b);
+  return b;
 }
 
 struct fastbuf *fbgrow_create(unsigned basic_size)
index 9bbd2f981c88cbbc4ac9e069da37b6ab95308bf7..75733fba9537486f4d7ecefe8aed92fb48880614 100644 (file)
@@ -55,7 +55,7 @@ bopen_limited_fd(int fd, uns buflen, uns limit)
   f->refill = bfl_refill;
   f->close = bfl_close;
   f->can_overwrite_buffer = 2;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
index bacdf03ff10260d7eb83ff2527297d18bb89f60d..61e94dadb52ed2ace1d074a317e3d8d5b9762506 100644 (file)
@@ -162,7 +162,7 @@ fbmem_create(unsigned blocksize)
   f->name = "<fbmem-write>";
   f->spout = fbmem_spout;
   f->close = fbmem_close;
-  return fb_tie(f);
+  return f;
 }
 
 struct fastbuf *
@@ -180,7 +180,7 @@ fbmem_clone_read(struct fastbuf *b)
   f->seek = fbmem_seek;
   f->close = fbmem_close;
   f->can_overwrite_buffer = 1;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
index b6a61248cf42a7ed15fa2da2b70aaff1f1a3fc3e..2704d07362550209b7b9a4c3bd5a10a88904538b 100644 (file)
@@ -192,7 +192,7 @@ bfmmopen_internal(int fd, const char *name, uns mode)
   f->seek = bfmm_seek;
   f->close = bfmm_close;
   f->config = bfmm_config;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST
index ae22e7227ed514575451718bf7689bbab917e468..dce8fffde2d540ebdde0c9992cd2e64bb8b4447b 100644 (file)
@@ -125,7 +125,7 @@ fbsock_create(struct fbsock_params *p)
   f->spout = fbs_spout;
   f->close = fbs_close;
   f->can_overwrite_buffer = 1;
-  return fb_tie(f);
+  return f;
 }
 
 #ifdef TEST