Completly disable all pthread related code in the library if USE_GLOBAL_CONTEXT macro is not defined. (#2302)

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni
2024-02-03 11:53:49 +01:00
committed by GitHub
parent 9af2b9d815
commit b59994fa20
3 changed files with 15 additions and 5 deletions
+5
View File
@@ -25,9 +25,12 @@ E * ndpi_typedefs.h
#define __NDPI_TYPEDEFS_H__ #define __NDPI_TYPEDEFS_H__
#ifndef NDPI_CFFI_PREPROCESSING #ifndef NDPI_CFFI_PREPROCESSING
#include "ndpi_config.h"
#ifdef USE_GLOBAL_CONTEXT
#define HAVE_STRUCT_TIMESPEC #define HAVE_STRUCT_TIMESPEC
#include <pthread.h> #include <pthread.h>
#endif #endif
#endif
#include "ndpi_define.h" #include "ndpi_define.h"
#ifndef NDPI_CFFI_PREPROCESSING #ifndef NDPI_CFFI_PREPROCESSING
@@ -769,7 +772,9 @@ struct ndpi_lru_cache {
u_int32_t num_entries; u_int32_t num_entries;
u_int32_t ttl : 31, shared : 1; u_int32_t ttl : 31, shared : 1;
#ifndef NDPI_CFFI_PREPROCESSING #ifndef NDPI_CFFI_PREPROCESSING
#ifdef USE_GLOBAL_CONTEXT
pthread_mutex_t mutex; pthread_mutex_t mutex;
#endif
#endif #endif
struct ndpi_lru_cache_stats stats; struct ndpi_lru_cache_stats stats;
struct ndpi_lru_cache_entry *entries; struct ndpi_lru_cache_entry *entries;
+8 -3
View File
@@ -3093,11 +3093,9 @@ static void free_ptree_data(void *data) {
} }
struct ndpi_global_context *ndpi_global_init(void) { struct ndpi_global_context *ndpi_global_init(void) {
#ifndef USE_GLOBAL_CONTEXT #ifndef USE_GLOBAL_CONTEXT
return NULL; return NULL;
#endif #else
struct ndpi_global_context *g_ctx = ndpi_calloc(1, sizeof(struct ndpi_global_context)); struct ndpi_global_context *g_ctx = ndpi_calloc(1, sizeof(struct ndpi_global_context));
if(g_ctx == NULL) if(g_ctx == NULL)
@@ -3109,6 +3107,7 @@ struct ndpi_global_context *ndpi_global_init(void) {
/* Note that we don't have yet an easy way to log from this function */ /* Note that we don't have yet an easy way to log from this function */
return g_ctx; return g_ctx;
#endif
} }
/* ******************************************************************** */ /* ******************************************************************** */
@@ -9868,12 +9867,14 @@ struct ndpi_lru_cache *ndpi_lru_cache_init(u_int32_t num_entries, u_int32_t ttl,
c->ttl = ttl & 0x7FFFFFFF; c->ttl = ttl & 0x7FFFFFFF;
c->shared = !!shared; c->shared = !!shared;
#ifdef USE_GLOBAL_CONTEXT
if(c->shared) { if(c->shared) {
if(pthread_mutex_init(&c->mutex, NULL) != 0) { if(pthread_mutex_init(&c->mutex, NULL) != 0) {
ndpi_free(c); ndpi_free(c);
return(NULL); return(NULL);
} }
} }
#endif
c->entries = (struct ndpi_lru_cache_entry *) ndpi_calloc(num_entries, sizeof(struct ndpi_lru_cache_entry)); c->entries = (struct ndpi_lru_cache_entry *) ndpi_calloc(num_entries, sizeof(struct ndpi_lru_cache_entry));
if(!c->entries) { if(!c->entries) {
@@ -9892,16 +9893,20 @@ void ndpi_lru_free_cache(struct ndpi_lru_cache *c) {
static void __lru_cache_lock(struct ndpi_lru_cache *c) static void __lru_cache_lock(struct ndpi_lru_cache *c)
{ {
#ifdef USE_GLOBAL_CONTEXT
if(c->shared) { if(c->shared) {
pthread_mutex_lock(&c->mutex); pthread_mutex_lock(&c->mutex);
} }
#endif
} }
static void __lru_cache_unlock(struct ndpi_lru_cache *c) static void __lru_cache_unlock(struct ndpi_lru_cache *c)
{ {
#ifdef USE_GLOBAL_CONTEXT
if(c->shared) { if(c->shared) {
pthread_mutex_unlock(&c->mutex); pthread_mutex_unlock(&c->mutex);
} }
#endif
} }
u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key,
+2 -2
View File
@@ -103,7 +103,7 @@ check_results() {
done done
fi fi
if [ $SKIP_PCAP -eq 1 ]; then if [ $SKIP_PCAP -eq 1 ]; then
printf "%-32s\tSKIPPED\n" "$f" printf "%-48s\tSKIPPED\n" "$f"
continue continue
fi fi
@@ -165,7 +165,7 @@ for d in $(find ./cfgs/* -type d -maxdepth 0 2>/dev/null) ; do
done done
fi fi
if [ $SKIP_CFG -eq 1 ]; then if [ $SKIP_CFG -eq 1 ]; then
printf "Configuration \""$(basename $d)"\" \tSKIPPED\n" printf "Configuration \""$(basename $d)"\" %-18s\tSKIPPED\n"
continue continue
fi fi