diff --git a/adapter/Makefile b/adapter/Makefile index ccbc5b72b..e759f4a55 100644 --- a/adapter/Makefile +++ b/adapter/Makefile @@ -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 diff --git a/adapter/ff_hook_syscall.c b/adapter/ff_hook_syscall.c index 26bcdcd9d..3a6ff5f65 100644 --- a/adapter/ff_hook_syscall.c +++ b/adapter/ff_hook_syscall.c @@ -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; diff --git a/adapter/ff_socket_ops.h b/adapter/ff_socket_ops.h index df0405364..63b12857d 100644 --- a/adapter/ff_socket_ops.h +++ b/adapter/ff_socket_ops.h @@ -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 {