[PATCH] blkparse: invert alloc checks, more intuitive
authorJens Axboe <axboe@suse.de>
Fri, 30 Sep 2005 10:34:19 +0000 (12:34 +0200)
committerJens Axboe <axboe@suse.de>
Fri, 30 Sep 2005 10:34:19 +0000 (12:34 +0200)
blkparse.c

index d9083004191e5acd1570c631394b20c6c85f360c..b0f45f0fde54fb2e944a9b26d890b5eee80c7e92 100644 (file)
@@ -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));
 }