util-thash.h File Reference
#include "threads.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_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)


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)
void THashDataMoveToSpare (THashTableContext *ctx, THashData *h)



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 78 of file util-thash.h.


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

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


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

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



Spinlocks or Mutex for the queues.

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


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

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


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

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


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

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


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

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


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

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



Spinlocks or Mutex for the buckets.

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


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

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


#define HRLOCK_TYPE   SCMutex

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


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

Definition at line 55 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 163 of file util-thash.h.


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

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

◆ THashDecrUsecnt

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

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

◆ THashIncrUsecnt

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

Definition at line 166 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 122 of file util-thash.h.

◆ THashOutputFunc

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

Definition at line 121 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 416 of file util-thash.c.

References THashTableContext_::array, THashTableContext_::config, THashDataConfig_::hash_size, HRLOCK_LOCK, HRLOCK_UNLOCK, THashData_::next, THashData_::prev, SC_ATOMIC_GET, and THashDataMoveToSpare().

Here is the call graph for this function:

◆ THashConsolidateMemcap()

void THashConsolidateMemcap ( THashTableContext ctx)

◆ THashDataMoveToSpare()

void THashDataMoveToSpare ( THashTableContext ctx,
THashData h 

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

Referenced by THashCleanup().

Here is the caller graph for this function:

◆ THashDataQueueNew()

THashDataQueue* THashDataQueueNew ( void  )

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

References SCLogError, and SCMalloc.

◆ THashGetFromHash()

struct THashDataGetResult THashGetFromHash ( THashTableContext ctx,
void *  data 

Definition at line 483 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 640 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 775 of file util-thash.c.

◆ THashShutdown()

void THashShutdown ( THashTableContext ctx)

shutdown the flow engine

Not thread safe

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

Referenced by HttpRangeContainersDestroy().

Here is the caller graph for this function:

◆ 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.