Source
void zbx_pp_history_cache_history_set_and_release(zbx_pp_history_cache_t *history_cache, zbx_pp_history_t *history_in,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
ZBX_VECTOR_IMPL(pp_step_history, zbx_pp_step_history_t)
struct zbx_pp_history_cache
{
pthread_mutex_t lock;
zbx_pp_history_t *history;
unsigned int refcount;
};
/******************************************************************************
* *
* Purpose: create preprocessing history *
* *
* Parameters: history_num - [IN] number of steps using history *
* *
* Return value: The created preprocessing history. *
* *
******************************************************************************/
zbx_pp_history_t *zbx_pp_history_create(int history_num)
{
zbx_pp_history_t *history = (zbx_pp_history_t *)zbx_malloc(NULL, sizeof(zbx_pp_history_t));
history->refcount = 1;
zbx_vector_pp_step_history_create(&history->step_history);
if (0 != history_num)
zbx_vector_pp_step_history_reserve(&history->step_history, (size_t)history_num);
return history;
}
zbx_pp_history_t *zbx_pp_history_release(zbx_pp_history_t *history)
{
if (NULL == history || 0 != --history->refcount)
return history;
for (int i = 0; i < history->step_history.values_num; i++)
zbx_variant_clear(&history->step_history.values[i].value);
zbx_vector_pp_step_history_destroy(&history->step_history);
zbx_free(history);
return NULL;
}