Go to the documentation of this file.
26 #ifndef SURICATA_THASH_H
27 #define SURICATA_THASH_H
37 #error Cannot enable both HRLOCK_SPIN and HRLOCK_MUTEX
42 #define HRLOCK_TYPE SCSpinlock
43 #define HRLOCK_INIT(fb) SCSpinInit(&(fb)->lock, 0)
44 #define HRLOCK_DESTROY(fb) SCSpinDestroy(&(fb)->lock)
45 #define HRLOCK_LOCK(fb) SCSpinLock(&(fb)->lock)
46 #define HRLOCK_TRYLOCK(fb) SCSpinTrylock(&(fb)->lock)
47 #define HRLOCK_UNLOCK(fb) SCSpinUnlock(&(fb)->lock)
48 #elif defined HRLOCK_MUTEX
49 #define HRLOCK_TYPE SCMutex
50 #define HRLOCK_INIT(fb) SCMutexInit(&(fb)->lock, NULL)
51 #define HRLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->lock)
52 #define HRLOCK_LOCK(fb) SCMutexLock(&(fb)->lock)
53 #define HRLOCK_TRYLOCK(fb) SCMutexTrylock(&(fb)->lock)
54 #define HRLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->lock)
56 #error Enable HRLOCK_SPIN or HRLOCK_MUTEX
65 #error Cannot enable both HQLOCK_SPIN and HQLOCK_MUTEX
70 #define HQLOCK_INIT(q) SCSpinInit(&(q)->s, 0)
71 #define HQLOCK_DESTROY(q) SCSpinDestroy(&(q)->s)
72 #define HQLOCK_LOCK(q) SCSpinLock(&(q)->s)
73 #define HQLOCK_TRYLOCK(q) SCSpinTrylock(&(q)->s)
74 #define HQLOCK_UNLOCK(q) SCSpinUnlock(&(q)->s)
75 #elif defined HQLOCK_MUTEX
76 #define HQLOCK_INIT(q) SCMutexInit(&(q)->m, NULL)
77 #define HQLOCK_DESTROY(q) SCMutexDestroy(&(q)->m)
78 #define HQLOCK_LOCK(q) SCMutexLock(&(q)->m)
79 #define HQLOCK_TRYLOCK(q) SCMutexTrylock(&(q)->m)
80 #define HQLOCK_UNLOCK(q) SCMutexUnlock(&(q)->m)
82 #error Enable HQLOCK_SPIN or HQLOCK_MUTEX
114 #elif defined HQLOCK_SPIN
117 #error Enable HQLOCK_SPIN or HQLOCK_MUTEX
121 typedef int (*
THashOutputFunc)(
void *output_ctx,
const uint8_t *data,
const uint32_t data_len);
122 typedef int (*
THashFormatFunc)(
const void *in_data,
char *output,
size_t output_size);
139 #define THASH_DATA_SIZE(ctx) (sizeof(THashData) + (ctx)->config.data_size)
164 #define THASH_CHECK_MEMCAP(ctx, size) \
165 ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= \
166 SC_ATOMIC_GET((ctx)->config.memcap)))
168 #define THashIncrUsecnt(h) \
169 (void)SC_ATOMIC_ADD((h)->use_cnt, 1)
170 #define THashDecrUsecnt(h) \
171 (void)SC_ATOMIC_SUB((h)->use_cnt, 1)
174 int (*DataSet)(
void *
dst,
void *
src),
void (*DataFree)(
void *),
175 uint32_t (*DataHash)(uint32_t,
void *),
bool (*DataCompare)(
void *,
void *),
176 bool (*DataExpired)(
void *,
SCTime_t), uint32_t (*DataSize)(
void *),
bool reset_memcap,
177 uint64_t memcap, uint32_t
hashsize);
181 static inline void THashDataLock(
THashData *d)
186 static inline void THashDataUnlock(
THashData *d)
SC_ATOMIC_DECLARE(uint32_t, counter)
THashDataQueue * THashDataQueueNew(void)
struct THashData_ THashData
int(* THashOutputFunc)(void *output_ctx, const uint8_t *data, const uint32_t data_len)
void THashShutdown(THashTableContext *ctx)
shutdown the flow engine
SC_ATOMIC_DECLARE(uint64_t, memcap)
void THashConsolidateMemcap(THashTableContext *ctx)
int THashWalk(THashTableContext *, THashFormatFunc, THashOutputFunc, void *)
Walk the hash.
bool(* DataCompare)(void *, void *)
struct THashDataQueue_ THashDataQueue
int(* DataSet)(void *dst, void *src)
struct THashHashRow_ __attribute__((aligned(CLS))) THashHashRow
#define SCMutexUnlock(mut)
uint32_t THashExpire(THashTableContext *ctx, const SCTime_t ts)
expire data from the hash Walk the hash table and remove data that is exprired according to the DataE...
int THashRemoveFromHash(THashTableContext *ctx, void *data)
uint32_t(* DataSize)(void *)
SC_ATOMIC_DECLARE(uint32_t, prune_idx)
SC_ATOMIC_DECLARE(unsigned int, use_cnt)
struct THashDataConfig_ THashConfig
struct THashDataGetResult THashGetFromHash(THashTableContext *ctx, void *data)
SC_ATOMIC_DECLARE(bool, memcap_reached)
bool(* DataExpired)(void *, SCTime_t ts)
THashTableContext * THashInit(const char *cnf_prefix, size_t data_size, int(*DataSet)(void *dst, void *src), void(*DataFree)(void *), uint32_t(*DataHash)(uint32_t, void *), bool(*DataCompare)(void *, void *), bool(*DataExpired)(void *, SCTime_t), uint32_t(*DataSize)(void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
void THashDataMoveToSpare(THashTableContext *ctx, THashData *h)
THashData * THashLookupFromHash(THashTableContext *ctx, void *data)
look up data in the hash
struct THashTableContext_ THashTableContext
int(* THashFormatFunc)(const void *in_data, char *output, size_t output_size)
uint32_t(* DataHash)(uint32_t, void *)
void THashCleanup(THashTableContext *ctx)
Cleanup the thash engine.
SC_ATOMIC_DECLARE(uint64_t, memuse)