2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2018 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com>
8 #define BT_LOG_TAG "CTF-WRITER/OBJECT-POOL"
13 #include "common/assert.h"
15 #include "object-pool.h"
17 int bt_ctf_object_pool_initialize(struct bt_ctf_object_pool
*pool
,
18 bt_ctf_object_pool_new_object_func new_object_func
,
19 bt_ctf_object_pool_destroy_object_func destroy_object_func
,
24 BT_ASSERT_DBG(new_object_func
);
25 BT_ASSERT_DBG(destroy_object_func
);
26 BT_LOGD("Initializing object pool: addr=%p, data-addr=%p",
28 pool
->objects
= g_ptr_array_new();
30 BT_LOGE_STR("Failed to allocate a GPtrArray.");
34 pool
->funcs
.new_object
= new_object_func
;
35 pool
->funcs
.destroy_object
= destroy_object_func
;
38 BT_LOGD("Initialized object pool.");
43 bt_ctf_object_pool_finalize(pool
);
52 void bt_ctf_object_pool_finalize(struct bt_ctf_object_pool
*pool
)
57 BT_LOGD("Finalizing object pool.");
60 for (i
= 0; i
< pool
->size
; i
++) {
61 void *obj
= pool
->objects
->pdata
[i
];
64 pool
->funcs
.destroy_object(obj
, pool
->data
);
68 g_ptr_array_free(pool
->objects
, TRUE
);