util-thash.h File Reference
#include "decode.h"
#include "util-storage.h"
Include dependency graph for util-thash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  THashData_
struct  THashHashRow_
struct  THashDataQueue_
struct  THashDataConfig_
struct  THashTableContext_
struct  THashDataGetResult


#define HRLOCK_TYPE   SCMutex
#define HRLOCK_INIT(fb)   SCMutexInit(&(fb)->lock, NULL)
#define HRLOCK_DESTROY(fb)   SCMutexDestroy(&(fb)->lock)
#define HRLOCK_LOCK(fb)   SCMutexLock(&(fb)->lock)
#define HRLOCK_TRYLOCK(fb)   SCMutexTrylock(&(fb)->lock)
#define HRLOCK_UNLOCK(fb)   SCMutexUnlock(&(fb)->lock)
#define HQLOCK_INIT(q)   SCMutexInit(&(q)->m, NULL)
#define HQLOCK_DESTROY(q)   SCMutexDestroy(&(q)->m)
#define HQLOCK_LOCK(q)   SCMutexLock(&(q)->m)
#define HQLOCK_TRYLOCK(q)   SCMutexTrylock(&(q)->m)
#define HQLOCK_UNLOCK(q)   SCMutexUnlock(&(q)->m)
#define THASH_VERBOSE   0
#define THASH_QUIET   1
#define THASH_DATA_SIZE(ctx)   (sizeof(THashData) + (ctx)->config.data_size)
#define THASH_CHECK_MEMCAP(ctx, size)   ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= (ctx)->config.memcap))
 check if a memory alloc would fit in the memcap More...
#define THashIncrUsecnt(h)   (void)SC_ATOMIC_ADD((h)->use_cnt, 1)
#define THashDecrUsecnt(h)   (void)SC_ATOMIC_SUB((h)->use_cnt, 1)
#define THashReference(dst_h_ptr, h)
#define THashDeReference(src_h_ptr)


typedef struct THashData_ THashData
typedef struct THashDataQueue_ THashDataQueue
typedef int(* THashOutputFunc) (void *output_ctx, const uint8_t *data, const uint32_t data_len)
typedef int(* THashFormatFunc) (const void *in_data, char *output, size_t output_size)
typedef struct THashDataConfig_ THashConfig
typedef struct THashTableContext_ THashTableContext


struct THashHashRow_ __attribute__ ((aligned(CLS))) THashHashRow
THashTableContextTHashInit (const char *cnf_prefix, size_t data_size, int(*DataSet)(void *dst, void *src), void(*DataFree)(void *), uint32_t(*DataHash)(void *), bool(*DataCompare)(void *, void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
void THashShutdown (THashTableContext *ctx)
 shutdown the flow engine More...
struct THashDataGetResult THashGetFromHash (THashTableContext *ctx, void *data)
THashDataTHashLookupFromHash (THashTableContext *ctx, void *data)
 look up data in the hash More...
THashDataQueueTHashDataQueueNew (void)
void THashCleanup (THashTableContext *ctx)
 Cleanup the thash engine. More...
int THashWalk (THashTableContext *, THashFormatFunc, THashOutputFunc, void *)
 Walk the hash. More...
int THashRemoveFromHash (THashTableContext *ctx, void *data)
void THashConsolidateMemcap (THashTableContext *ctx)



Detailed Description

Victor Julien

thash -> thread hash. Hash table with locking handling.

Definition in file util-thash.h.

Macro Definition Documentation


#define HQLOCK_DESTROY (   q)    SCMutexDestroy(&(q)->m)

Definition at line 79 of file util-thash.h.


#define HQLOCK_INIT (   q)    SCMutexInit(&(q)->m, NULL)

Definition at line 78 of file util-thash.h.


#define HQLOCK_LOCK (   q)    SCMutexLock(&(q)->m)

Definition at line 80 of file util-thash.h.



Spinlocks or Mutex for the queues.

Definition at line 63 of file util-thash.h.


#define HQLOCK_TRYLOCK (   q)    SCMutexTrylock(&(q)->m)

Definition at line 81 of file util-thash.h.


#define HQLOCK_UNLOCK (   q)    SCMutexUnlock(&(q)->m)

Definition at line 82 of file util-thash.h.


#define HRLOCK_DESTROY (   fb)    SCMutexDestroy(&(fb)->lock)

Definition at line 53 of file util-thash.h.


#define HRLOCK_INIT (   fb)    SCMutexInit(&(fb)->lock, NULL)

Definition at line 52 of file util-thash.h.


#define HRLOCK_LOCK (   fb)    SCMutexLock(&(fb)->lock)

Definition at line 54 of file util-thash.h.



Spinlocks or Mutex for the buckets.

Definition at line 35 of file util-thash.h.


#define HRLOCK_TRYLOCK (   fb)    SCMutexTrylock(&(fb)->lock)

Definition at line 55 of file util-thash.h.


#define HRLOCK_TYPE   SCMutex

Definition at line 51 of file util-thash.h.


#define HRLOCK_UNLOCK (   fb)    SCMutexUnlock(&(fb)->lock)

Definition at line 56 of file util-thash.h.


#define THASH_CHECK_MEMCAP (   ctx,
)    ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= (ctx)->config.memcap))

check if a memory alloc would fit in the memcap

sizememory allocation size to check
Return values
1it fits
0no fit

Definition at line 167 of file util-thash.h.


#define THASH_DATA_SIZE (   ctx)    (sizeof(THashData) + (ctx)->config.data_size)

Definition at line 142 of file util-thash.h.


#define THASH_QUIET   1

Definition at line 124 of file util-thash.h.


#define THASH_VERBOSE   0

Definition at line 123 of file util-thash.h.

◆ THashDecrUsecnt

#define THashDecrUsecnt (   h)    (void)SC_ATOMIC_SUB((h)->use_cnt, 1)

Definition at line 172 of file util-thash.h.

◆ THashDeReference

#define THashDeReference (   src_h_ptr)
do { \
if (*(src_h_ptr) != NULL) { \
THashDecrUsecnt(*(src_h_ptr)); \
*(src_h_ptr) = NULL; \
} \
} while (0)

Definition at line 182 of file util-thash.h.

◆ THashIncrUsecnt

#define THashIncrUsecnt (   h)    (void)SC_ATOMIC_ADD((h)->use_cnt, 1)

Definition at line 170 of file util-thash.h.

◆ THashReference

#define THashReference (   dst_h_ptr,
do { \
if ((h) != NULL) { \
THashIncrUsecnt((h)); \
*(dst_h_ptr) = h; \
} \
} while (0)

Definition at line 175 of file util-thash.h.

Typedef Documentation

◆ THashConfig

typedef struct THashDataConfig_ THashConfig

◆ THashData

typedef struct THashData_ THashData

◆ THashDataQueue

◆ THashFormatFunc

typedef int(* THashFormatFunc) (const void *in_data, char *output, size_t output_size)

Definition at line 126 of file util-thash.h.

◆ THashOutputFunc

typedef int(* THashOutputFunc) (void *output_ctx, const uint8_t *data, const uint32_t data_len)

Definition at line 125 of file util-thash.h.

◆ THashTableContext

Function Documentation

◆ __attribute__()

struct THashHashRow_ __attribute__ ( (aligned(CLS))  )

◆ THashCleanup()

void THashCleanup ( THashTableContext ctx)

Cleanup the thash engine.

Cleanup the thash engine from tag and threshold.

Definition at line 407 of file util-thash.c.

References THashTableContext_::array, THashTableContext_::config, THashDataConfig_::hash_size, HRLOCK_LOCK, THashData_::next, THashData_::prev, and SC_ATOMIC_GET.

◆ THashConsolidateMemcap()

void THashConsolidateMemcap ( THashTableContext ctx)

◆ THashDataQueueNew()

THashDataQueue* THashDataQueueNew ( void  )

Definition at line 55 of file util-thash.c.

References SC_ERR_FATAL, SCLogError, and SCMalloc.

◆ THashGetFromHash()

struct THashDataGetResult THashGetFromHash ( THashTableContext ctx,
void *  data 

Definition at line 474 of file util-thash.c.

◆ THashInit()

THashTableContext* THashInit ( const char *  cnf_prefix,
size_t  data_size,
int(*)(void *dst, void *src DataSet,
void(*)(void *)  DataFree,
uint32_t(*)(void *)  DataHash,
bool(*)(void *, void *)  DataCompare,
bool  reset_memcap,
uint64_t  memcap,
uint32_t  hashsize 

◆ THashLookupFromHash()

THashData* THashLookupFromHash ( THashTableContext ctx,
void *  data 

look up data in the hash

datadata to look up
Return values
hLOCKED data or NULL

Definition at line 631 of file util-thash.c.

◆ THashRemoveFromHash()

int THashRemoveFromHash ( THashTableContext ctx,
void *  data 
Return values
int-1 not found
int0 found, but it was busy (ref cnt)
int1 found and removed

Definition at line 766 of file util-thash.c.

◆ THashShutdown()

void THashShutdown ( THashTableContext ctx)

shutdown the flow engine

Not thread safe

Definition at line 337 of file util-thash.c.

◆ THashWalk()

int THashWalk ( THashTableContext ctx,
THashFormatFunc  FormatterFunc,
THashOutputFunc  OutputterFunc,
void *  output_ctx 

Variable Documentation

◆ head

THashData* head

Definition at line 1 of file util-thash.h.

◆ lock

Definition at line 0 of file util-thash.h.

◆ tail

THashData* tail

Definition at line 2 of file util-thash.h.