// SPDX-License-Identifier: GPL-3.0-or-later
#include "internal.h"
#define QUERY_TARGET_MAX_REALLOC_INCREASE 500
#define query_target_realloc_size(size, start) \
(size) ? ((size) < QUERY_TARGET_MAX_REALLOC_INCREASE ? (size) * 2 : (size) + QUERY_TARGET_MAX_REALLOC_INCREASE) : (start);
static void query_metric_release(QUERY_TARGET *qt, QUERY_METRIC *qm);
static void query_dimension_release(QUERY_DIMENSION *qd);
static void query_instance_release(QUERY_INSTANCE *qi);
static void query_context_release(QUERY_CONTEXT *qc);
static void query_node_release(QUERY_NODE *qn);
static __thread QUERY_TARGET *thread_qt = NULL;
static struct {
struct {
SPINLOCK spinlock;
size_t count;
QUERY_TARGET *base;
} available;
struct {
SPINLOCK spinlock;
size_t count;
QUERY_TARGET *base;
} used;
} query_target_base = {
.available = {
.spinlock = NETDATA_SPINLOCK_INITIALIZER,
.base = NULL,
.count = 0,
},
.used = {
.spinlock = NETDATA_SPINLOCK_INITIALIZER,
.base = NULL,
.count = 0,
},
};
static void query_target_destroy(QUERY_TARGET *qt) {
__atomic_sub_fetch(&netdata_buffers_statistics.query_targets_size, qt->query.size * sizeof(*qt->query.array), __ATOMIC_RELAXED);
freez(qt->query.array);
__atomic_sub_fetch(&netdata_buffers_statistics.query_targets_size, qt->dimensions.size * sizeof(*qt->dimensions.array), __ATOMIC_RELAXED);
freez(qt->dimensions.array);
__atomic_sub_fetch(&netdata_buffers_statistics.query_targets_size, qt->instances.size * sizeof(*qt->instances.array), __ATOMIC_RELAXED);
freez(qt->instances.array);
__atomic_sub_fetch(&netdata_buffers_statistics.query_targets_size, qt->contexts.size * sizeof(*qt->contexts.array), __ATOMIC_RELAXED);
freez(qt->contexts.array);
__atomic_sub_fetch(&netdata_buffers_statistics.query_targets_size, qt->nodes.size * sizeof(*qt->nodes.array), __ATOMIC_RELAXED);
freez(qt->nodes.array);
freez(qt);
}
void query_target_release(QUERY_TARGET *qt) {
if(unlikely(!