Source
memmove(queue->values, queue->values + queue->tail_pos, values_num * sizeof(*queue->values));
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/******************************************************************************
* *
* Purpose: calculates the number of values in queue *
* *
* Parameters: queue - [IN] the queue *
* *
* Return value: The number of values in queue *
* *
******************************************************************************/
int zbx_queue_ptr_values_num(zbx_queue_ptr_t *queue)
{
int values_num;
values_num = queue->head_pos - queue->tail_pos;
if (0 > values_num)
values_num += queue->alloc_num;
return values_num;
}
/******************************************************************************
* *
* Purpose: reserves space in queue for additional values *
* *
* Parameters: queue - [IN] the queue *
* num - [IN] the number of additional values to reserve *
* *
******************************************************************************/
void zbx_queue_ptr_reserve(zbx_queue_ptr_t *queue, int num)
{
int values_num, alloc_num, resize_num;
values_num = zbx_queue_ptr_values_num(queue);
if (values_num + num + 1 <= queue->alloc_num)
return;
alloc_num = queue->alloc_num + MAX(num + 1, queue->alloc_num / 2);
queue->values = (void **)zbx_realloc(queue->values, alloc_num * sizeof(*queue->values));