int zbx_tfc_get_value(zbx_uint64_t itemid, time_t start, time_t end, zbx_trend_function_t function, double *value,
#include "zbxtrends.h"
#include "trends.h"
#include "zbxalgo.h"
#include "zbxmutexs.h"
#include "zbxshmem.h"
#include "zbxnum.h"
#include "zbxstr.h"
typedef struct
{
zbx_uint64_t itemid;
int start;
int end;
zbx_trend_function_t function;
zbx_trend_state_t state;
double value;
zbx_uint32_t prev;
zbx_uint32_t next;
zbx_uint32_t prev_value;
zbx_uint32_t next_value;
}
zbx_tfc_data_t;
typedef struct
{
char header[ZBX_HASHSET_ENTRY_OFFSET];
zbx_tfc_data_t data;
}
zbx_tfc_slot_t;
typedef struct
{
zbx_hashset_t index;
zbx_tfc_slot_t *slots;
size_t slots_size;
zbx_uint32_t slots_num;
zbx_uint32_t free_slot;
zbx_uint32_t free_head;
zbx_uint32_t lru_head;
zbx_uint32_t lru_tail;
zbx_uint64_t hits;
zbx_uint64_t misses;
zbx_uint64_t items_num;
zbx_uint64_t conf_size;
}
zbx_tfc_t;
static zbx_tfc_t *cache = NULL;
static int alloc_num = 0;
static zbx_shmem_info_t *tfc_mem = NULL;
static zbx_mutex_t tfc_lock = ZBX_MUTEX_NULL;
ZBX_SHMEM_FUNC_IMPL(__tfc, tfc_mem)
#define LOCK_CACHE zbx_mutex_lock(tfc_lock)
#define UNLOCK_CACHE zbx_mutex_unlock(tfc_lock)
static void tfc_free_slot(zbx_tfc_slot_t *slot)
{
zbx_uint32_t index = slot - cache->slots;
slot->data.next = cache->free_head;
slot->data.prev = UINT32_MAX;
cache->free_head = index;
}
static zbx_tfc_slot_t *tfc_alloc_slot(void)
{
zbx_uint32_t index;