From 3c8413cb8d85f28622e9fefb5a6bcb0705f3b26f Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 30 Sep 2005 12:34:19 +0200 Subject: [PATCH] [PATCH] blkparse: invert alloc checks, more intuitive --- blkparse.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/blkparse.c b/blkparse.c index d908300..b0f45f0 100644 --- a/blkparse.c +++ b/blkparse.c @@ -1186,13 +1186,12 @@ static void show_device_and_cpu_stats(void) */ static inline void t_free(struct trace *t) { - if (t_alloc_cache > 1024) { - free(t); - t_alloc_cache--; - } else { + if (t_alloc_cache < 1024) { t->next = t_alloc_list; t_alloc_list = t; - } + t_alloc_cache++; + } else + free(t); } static inline struct trace *t_alloc(void) @@ -1201,25 +1200,24 @@ static inline struct trace *t_alloc(void) if (t) { t_alloc_list = t->next; + t_alloc_cache--; return t; } - t_alloc_cache++; return malloc(sizeof(*t)); } static inline void bit_free(struct blk_io_trace *bit) { - if (bit_alloc_cache > 1024) { - free(bit); - bit_alloc_cache--; - } else { + if (bit_alloc_cache < 1024) { /* * abuse a 64-bit field for a next pointer for the free item */ bit->time = (__u64) (unsigned long) bit_alloc_list; bit_alloc_list = (struct blk_io_trace *) bit; - } + bit_alloc_cache++; + } else + free(bit); } static inline struct blk_io_trace *bit_alloc(void) @@ -1229,10 +1227,10 @@ static inline struct blk_io_trace *bit_alloc(void) if (bit) { bit_alloc_list = (struct blk_io_trace *) (unsigned long) \ bit->time; + bit_alloc_cache--; return bit; } - bit_alloc_cache++; return malloc(sizeof(*bit)); } -- 2.25.1