2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <common/dynamic-array.h>
21 void lttng_dynamic_array_init(struct lttng_dynamic_array
*array
,
24 lttng_dynamic_buffer_init(&array
->buffer
);
25 array
->element_size
= element_size
;
29 int lttng_dynamic_array_add_element(struct lttng_dynamic_array
*array
,
34 if (!array
|| !element
) {
39 ret
= lttng_dynamic_buffer_append(&array
->buffer
, element
,
50 void lttng_dynamic_array_reset(struct lttng_dynamic_array
*array
,
51 lttng_dynamic_array_element_destructor destructor
)
56 for (i
= 0; i
< lttng_dynamic_array_get_count(array
); i
++) {
57 destructor(lttng_dynamic_array_get_element(array
, i
));
61 lttng_dynamic_buffer_reset(&array
->buffer
);
66 void lttng_dynamic_pointer_array_init(
67 struct lttng_dynamic_pointer_array
*array
)
69 lttng_dynamic_array_init(&array
->array
, sizeof(void *));
72 /* Release any memory used by the dynamic array. */
74 void lttng_dynamic_pointer_array_reset(
75 struct lttng_dynamic_pointer_array
*array
,
76 lttng_dynamic_pointer_array_destructor destructor
)
79 size_t i
, count
= lttng_dynamic_pointer_array_get_count(array
);
81 for (i
= 0; i
< count
; i
++) {
82 void *ptr
= lttng_dynamic_pointer_array_get_pointer(
87 lttng_dynamic_array_reset(&array
->array
, NULL
);