Add FF_THREAD_SOCKET in Makefile, Whether to use thread-level socket,

default enable.
This commit is contained in:
fengbojiang 2023-04-06 18:02:47 +08:00
parent 865ab0ed63
commit fe7e360eca
3 changed files with 30 additions and 8 deletions

View File

@ -8,15 +8,27 @@ ifneq ($(shell pkg-config --exists libdpdk && echo 0),0)
$(error "No installation of DPDK found, maybe you should export environment variable `PKG_CONFIG_PATH`")
endif
DEBUG=-O0 -gdwarf-2 -g3 -DDEBUG
DEBUG=-O0 -gdwarf-2 -g3
# Per thread separate initialization dpdk lib and attach sc when needed,
# such as listen same port in different threads, and socket can use in own thread.
# Default enable.
#
# If disable it, one socket can use in all threads.
FF_THREAD_SOCKET=1
PKGCONF ?= pkg-config
ifndef DEBUG
CFLAGS+= -g -O2
CFLAGS+= -g -O2 -DNDEBUG
else
CFLAGS+= ${DEBUG}
endif
ifdef FF_THREAD_SOCKET
CFLAGS+= -DFF_THREAD_SOCKET
endif
CFLAGS += -fPIC -Wall -Werror $(shell $(PKGCONF) --cflags libdpdk)
INCLUDES= -I. -I${FF_PATH}/lib

View File

@ -95,9 +95,19 @@
return ret; \
} while (0)
/* per thread separate initialization dpdk lib and attach sc */
static __thread int inited = 0;
static __thread struct ff_so_context *sc;
/*
* Per thread separate initialization dpdk lib and attach sc when needed,
* such as listen same port in different threads, and socket can use in own thread.
*
* Otherwise, one socket can use in all threads.
*/
#ifdef FF_THREAD_SOCKET
#define __FF_THREAD __thread
#else
#define __FF_THREAD
#endif
static __FF_THREAD int inited = 0;
static __FF_THREAD struct ff_so_context *sc;
/* process-level initialization flag */
static int proc_inited = 0;

View File

@ -10,10 +10,10 @@
printf("file:%s, line:%u, fun:%s, "fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
} while (0)
#ifdef DEBUG
#define DEBUG_LOG ERR_LOG
#else
#ifdef NDEBUG
#define DEBUG_LOG(...)
#else
#define DEBUG_LOG ERR_LOG
#endif
enum FF_SOCKET_OPS {