lib: internal: object-pool.h: require logging
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 21:01:51 +0000 (17:01 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 29 Jun 2019 06:04:08 +0000 (02:04 -0400)
This patch makes the internal `object-pool.h` require what it needs
instead of using the macros only if they exist. This makes it impossible
to skip logging in this header.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5f1b5550dfca7c7f3e8d62134a2917b059e4da0c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1580
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/lib/object-pool.h

index 24d1e540aeaf53132c5090b45baed88c6d3dd5e1..e94e04d24801a7b1b64c6e9ef8969a92dc4624db 100644 (file)
 #include <glib.h>
 #include "lib/object.h"
 
+/* Protection: this file uses BT_LIB_LOG*() macros directly */
+#ifndef BT_LIB_LOG_SUPPORTED
+# error Please include "lib/logging.h" before including this file.
+#endif
+
 typedef void *(*bt_object_pool_new_object_func)(void *data);
 typedef void *(*bt_object_pool_destroy_object_func)(void *obj, void *data);
 
@@ -107,11 +112,8 @@ void *bt_object_pool_create_object(struct bt_object_pool *pool)
        struct bt_object *obj;
 
        BT_ASSERT(pool);
-
-#ifdef BT_LOGT
        BT_LOGT("Creating object from pool: pool-addr=%p, pool-size=%zu, pool-cap=%u",
                pool, pool->size, pool->objects->len);
-#endif
 
        if (pool->size > 0) {
                /* Pick one from the pool */
@@ -122,19 +124,13 @@ void *bt_object_pool_create_object(struct bt_object_pool *pool)
        }
 
        /* Pool is empty: create a brand new object */
-#ifdef BT_LOGD
        BT_LOGD("Pool is empty: allocating new object: pool-addr=%p",
                pool);
-#endif
-
        obj = pool->funcs.new_object(pool->data);
 
 end:
-#ifdef BT_LOGT
        BT_LOGT("Created one object from pool: pool-addr=%p, obj-addr=%p",
                pool, obj);
-#endif
-
        return obj;
 }
 
@@ -150,19 +146,14 @@ void bt_object_pool_recycle_object(struct bt_object_pool *pool, void *obj)
 
        BT_ASSERT(pool);
        BT_ASSERT(obj);
-
-#ifdef BT_LOGT
        BT_LOGT("Recycling object: pool-addr=%p, pool-size=%zu, pool-cap=%u, obj-addr=%p",
                pool, pool->size, pool->objects->len, obj);
-#endif
 
        if (pool->size == pool->objects->len) {
                /* Backing array is full: make place for recycled object */
-#ifdef BT_LOGD
                BT_LOGD("Object pool is full: increasing object pool capacity: "
                        "pool-addr=%p, old-pool-cap=%u, new-pool-cap=%u",
                        pool, pool->objects->len, pool->objects->len + 1);
-#endif
                g_ptr_array_set_size(pool->objects, pool->size + 1);
        }
 
@@ -172,11 +163,8 @@ void bt_object_pool_recycle_object(struct bt_object_pool *pool, void *obj)
        /* Back to the pool */
        pool->objects->pdata[pool->size] = obj;
        pool->size++;
-
-#ifdef BT_LOGT
        BT_LOGT("Recycled object: pool-addr=%p, pool-size=%zu, pool-cap=%u, obj-addr=%p",
                pool, pool->size, pool->objects->len, obj);
-#endif
 }
 
 #endif /* BABELTRACE_OBJECT_POOL_INTERNAL_H */
This page took 0.026699 seconds and 4 git commands to generate.