From: Martin Mares Date: Tue, 19 Apr 2011 12:46:26 +0000 (+0200) Subject: Fastbufs are not tied to resources automatically any longer X-Git-Tag: v5.0~74^2~12 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=92c1eac70f981f73950853ecedf556d2a9addf8a;p=libucw.git Fastbufs are not tied to resources automatically any longer Explicit tying by fb_tie() should be used instead. --- diff --git a/ucw/doc/fastbuf.txt b/ucw/doc/fastbuf.txt index 86ab55d9..47109906 100644 --- a/ucw/doc/fastbuf.txt +++ b/ucw/doc/fastbuf.txt @@ -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: - <> diff --git a/ucw/fastbuf.c b/ucw/fastbuf.c index 4068aab8..7bec4bfd 100644 --- a/ucw/fastbuf.c +++ b/ucw/fastbuf.c @@ -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 */ diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index f418f667..99037524 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -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]] * diff --git a/ucw/fb-atomic.c b/ucw/fb-atomic.c index fca0dfb6..1dce8f08 100644 --- a/ucw/fb-atomic.c +++ b/ucw/fb-atomic.c @@ -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 diff --git a/ucw/fb-direct.c b/ucw/fb-direct.c index ccdb851b..eb1144ca 100644 --- a/ucw/fb-direct.c +++ b/ucw/fb-direct.c @@ -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 diff --git a/ucw/fb-file.c b/ucw/fb-file.c index cc5cf22c..a7af6108 100644 --- a/ucw/fb-file.c +++ b/ucw/fb-file.c @@ -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 diff --git a/ucw/fb-grow.c b/ucw/fb-grow.c index ab80be0b..803e411e 100644 --- a/ucw/fb-grow.c +++ b/ucw/fb-grow.c @@ -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) diff --git a/ucw/fb-limfd.c b/ucw/fb-limfd.c index 9bbd2f98..75733fba 100644 --- a/ucw/fb-limfd.c +++ b/ucw/fb-limfd.c @@ -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 diff --git a/ucw/fb-mem.c b/ucw/fb-mem.c index bacdf03f..61e94dad 100644 --- a/ucw/fb-mem.c +++ b/ucw/fb-mem.c @@ -162,7 +162,7 @@ fbmem_create(unsigned blocksize) f->name = ""; 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 diff --git a/ucw/fb-mmap.c b/ucw/fb-mmap.c index b6a61248..2704d073 100644 --- a/ucw/fb-mmap.c +++ b/ucw/fb-mmap.c @@ -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 diff --git a/ucw/fb-socket.c b/ucw/fb-socket.c index ae22e722..dce8fffd 100644 --- a/ucw/fb-socket.c +++ b/ucw/fb-socket.c @@ -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