From 903e6530eaa344851bf0aa6a9f270c205aa97300 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 17 Apr 2011 13:15:12 +0200 Subject: [PATCH] Resources: Simplified use of fb_tie() --- ucw/fastbuf.c | 5 +++-- ucw/fastbuf.h | 5 +++-- ucw/fb-atomic.c | 3 +-- ucw/fb-direct.c | 3 +-- ucw/fb-file.c | 3 +-- ucw/fb-grow.c | 3 +-- ucw/fb-limfd.c | 3 +-- ucw/fb-mem.c | 6 ++---- ucw/fb-mmap.c | 3 +-- ucw/fb-socket.c | 3 +-- 10 files changed, 15 insertions(+), 22 deletions(-) diff --git a/ucw/fastbuf.c b/ucw/fastbuf.c index 4cd8bdfd..83c3b079 100644 --- a/ucw/fastbuf.c +++ b/ucw/fastbuf.c @@ -1,7 +1,7 @@ /* * UCW Library -- Fast Buffered I/O * - * (c) 1997--2007 Martin Mares + * (c) 1997--2011 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -314,7 +314,8 @@ static const struct res_class fb_res_class = { .free = fb_res_free, }; -void fb_tie(struct fastbuf *f) +struct fastbuf *fb_tie(struct fastbuf *f) { f->res = res_new(&fb_res_class, f); + return f; } diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index 41f339ee..dfd29d00 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -1,7 +1,7 @@ /* * UCW Library -- Fast Buffered I/O * - * (c) 1997--2008 Martin Mares + * (c) 1997--2011 Martin Mares * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -101,6 +101,7 @@ * * - Initialization: * * out: `buffer <= bstop <= bptr <= bufend` (flushed). + * * @fb_tie() should be called on the newly created fastbuf. * * - `refill`: * * in: `buffer <= bstop <= bptr <= bufend` (reading or flushed). @@ -143,7 +144,7 @@ struct fastbuf { struct resource *res; /* The fastbuf can be tied to a resource pool */ }; -void fb_tie(struct fastbuf *b); /* Tie fastbuf to a resource if there is an active pool */ +struct fastbuf *fb_tie(struct fastbuf *b); /* Tie fastbuf to a resource if there is an active pool */ /** * Fastbuf flags diff --git a/ucw/fb-atomic.c b/ucw/fb-atomic.c index 1b4a07bb..fca0dfb6 100644 --- a/ucw/fb-atomic.c +++ b/ucw/fb-atomic.c @@ -133,8 +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; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST diff --git a/ucw/fb-direct.c b/ucw/fb-direct.c index 26490579..ccdb851b 100644 --- a/ucw/fb-direct.c +++ b/ucw/fb-direct.c @@ -308,8 +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; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST diff --git a/ucw/fb-file.c b/ucw/fb-file.c index 35adbae4..cc5cf22c 100644 --- a/ucw/fb-file.c +++ b/ucw/fb-file.c @@ -238,8 +238,7 @@ bfdopen_internal(int fd, const char *name, uns buflen) f->close = bfd_close; f->config = bfd_config; f->can_overwrite_buffer = 2; - fb_tie(f); - return f; + return fb_tie(f); } void diff --git a/ucw/fb-grow.c b/ucw/fb-grow.c index 27b5bf03..19880ed3 100644 --- a/ucw/fb-grow.c +++ b/ucw/fb-grow.c @@ -92,8 +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; - fb_tie(b); - return b; + return fb_tie(b); } struct fastbuf *fbgrow_create(unsigned basic_size) diff --git a/ucw/fb-limfd.c b/ucw/fb-limfd.c index f909da3b..9bbd2f98 100644 --- a/ucw/fb-limfd.c +++ b/ucw/fb-limfd.c @@ -55,8 +55,7 @@ bopen_limited_fd(int fd, uns buflen, uns limit) f->refill = bfl_refill; f->close = bfl_close; f->can_overwrite_buffer = 2; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST diff --git a/ucw/fb-mem.c b/ucw/fb-mem.c index 38fa9001..bacdf03f 100644 --- a/ucw/fb-mem.c +++ b/ucw/fb-mem.c @@ -162,8 +162,7 @@ fbmem_create(unsigned blocksize) f->name = ""; f->spout = fbmem_spout; f->close = fbmem_close; - fb_tie(f); - return f; + return fb_tie(f); } struct fastbuf * @@ -181,8 +180,7 @@ fbmem_clone_read(struct fastbuf *b) f->seek = fbmem_seek; f->close = fbmem_close; f->can_overwrite_buffer = 1; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST diff --git a/ucw/fb-mmap.c b/ucw/fb-mmap.c index d1882ee7..b6a61248 100644 --- a/ucw/fb-mmap.c +++ b/ucw/fb-mmap.c @@ -192,8 +192,7 @@ bfmmopen_internal(int fd, const char *name, uns mode) f->seek = bfmm_seek; f->close = bfmm_close; f->config = bfmm_config; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST diff --git a/ucw/fb-socket.c b/ucw/fb-socket.c index d90f7e7c..ae22e722 100644 --- a/ucw/fb-socket.c +++ b/ucw/fb-socket.c @@ -125,8 +125,7 @@ fbsock_create(struct fbsock_params *p) f->spout = fbs_spout; f->close = fbs_close; f->can_overwrite_buffer = 1; - fb_tie(f); - return f; + return fb_tie(f); } #ifdef TEST -- 2.39.5