@ -54,76 +54,12 @@
# define MAX_PENDING_RETURN_PACKETS 32
# define MAX_PENDING_RETURN_PACKETS 32
static uint32_t max_pending_return_packets = MAX_PENDING_RETURN_PACKETS ;
static uint32_t max_pending_return_packets = MAX_PENDING_RETURN_PACKETS ;
# ifdef TLS
thread_local PktPool thread_pkt_pool ;
__thread PktPool thread_pkt_pool ;
static inline PktPool * GetThreadPacketPool ( void )
static inline PktPool * GetThreadPacketPool ( void )
{
{
return & thread_pkt_pool ;
return & thread_pkt_pool ;
}
}
# else
/* __thread not supported. */
static pthread_key_t pkt_pool_thread_key ;
static SCMutex pkt_pool_thread_key_mutex = SCMUTEX_INITIALIZER ;
static int pkt_pool_thread_key_initialized = 0 ;
static void PktPoolThreadDestroy ( void * buf )
{
SCFreeAligned ( buf ) ;
}
static void TmqhPacketPoolInit ( void )
{
SCMutexLock ( & pkt_pool_thread_key_mutex ) ;
if ( pkt_pool_thread_key_initialized ) {
/* Key has already been created. */
SCMutexUnlock ( & pkt_pool_thread_key_mutex ) ;
return ;
}
/* Create the pthread Key that is used to look up thread specific
* data buffer . Needs to be created only once .
*/
int r = pthread_key_create ( & pkt_pool_thread_key , PktPoolThreadDestroy ) ;
if ( r ! = 0 ) {
SCLogError ( SC_ERR_MEM_ALLOC , " pthread_key_create failed with %d " , r ) ;
exit ( EXIT_FAILURE ) ;
}
pkt_pool_thread_key_initialized = 1 ;
SCMutexUnlock ( & pkt_pool_thread_key_mutex ) ;
}
static PktPool * ThreadPacketPoolCreate ( void )
{
TmqhPacketPoolInit ( ) ;
/* Create a new pool for this thread. */
PktPool * pool = ( PktPool * ) SCMallocAligned ( sizeof ( PktPool ) , CLS ) ;
if ( pool = = NULL ) {
SCLogError ( SC_ERR_MEM_ALLOC , " malloc failed " ) ;
exit ( EXIT_FAILURE ) ;
}
memset ( pool , 0x0 , sizeof ( * pool ) ) ;
int r = pthread_setspecific ( pkt_pool_thread_key , pool ) ;
if ( r ! = 0 ) {
SCLogError ( SC_ERR_MEM_ALLOC , " pthread_setspecific failed with %d " , r ) ;
exit ( EXIT_FAILURE ) ;
}
return pool ;
}
static inline PktPool * GetThreadPacketPool ( void )
{
PktPool * pool = ( PktPool * ) pthread_getspecific ( pkt_pool_thread_key ) ;
if ( pool = = NULL )
pool = ThreadPacketPoolCreate ( ) ;
return pool ;
}
# endif
/**
/**
* \ brief TmqhPacketpoolRegister
* \ brief TmqhPacketpoolRegister
@ -350,10 +286,6 @@ void PacketPoolReturnPacket(Packet *p)
void PacketPoolInitEmpty ( void )
void PacketPoolInitEmpty ( void )
{
{
# ifndef TLS
TmqhPacketPoolInit ( ) ;
# endif
PktPool * my_pool = GetThreadPacketPool ( ) ;
PktPool * my_pool = GetThreadPacketPool ( ) ;
# ifdef DEBUG_VALIDATION
# ifdef DEBUG_VALIDATION
@ -371,10 +303,6 @@ void PacketPoolInit(void)
{
{
extern intmax_t max_pending_packets ;
extern intmax_t max_pending_packets ;
# ifndef TLS
TmqhPacketPoolInit ( ) ;
# endif
PktPool * my_pool = GetThreadPacketPool ( ) ;
PktPool * my_pool = GetThreadPacketPool ( ) ;
# ifdef DEBUG_VALIDATION
# ifdef DEBUG_VALIDATION