summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2021-11-10 12:55:27 +0800
committerlijia <[email protected]>2021-11-10 12:55:27 +0800
commitbb08abbde07e2c5d322f5040ec67b42c992d176e (patch)
treed5e841585797637b1c706774434fb929fd09475b
parent571718c4da275ef2e8e6e2b3fef847b94dbe5d59 (diff)
修复多个流程同时调用libsapp_destroy_env()时, 可能会阻塞的问题.v4.2.67
-rw-r--r--src/sapp_dev/sapp_init.c7
-rw-r--r--src/sapp_dev/sapp_plug.c48
-rw-r--r--test/test_app_sapp.c30
3 files changed, 61 insertions, 24 deletions
diff --git a/src/sapp_dev/sapp_init.c b/src/sapp_dev/sapp_init.c
index 14b8457..04a48b0 100644
--- a/src/sapp_dev/sapp_init.c
+++ b/src/sapp_dev/sapp_init.c
@@ -57,10 +57,13 @@ extern char gdev_keepalive_ip_entry(const struct streaminfo *pstream,unsigned ch
extern char gdev_keepalive_udp_entry(const struct streaminfo *a_udp, void **pme, int thread_seq, const void *ip_hdr);
static int _check_exit_cap_mode;
-extern volatile unsigned long g_sapp_destory_env_done_val;
+extern volatile unsigned long g_sapp_destory_env_running_state;
+extern volatile unsigned long g_sapp_destory_env_done_state;
+
static void forbid_call_exit_in_running_state(void)
{
- if(SAPP_DESTROY_DONE_FLAG == g_sapp_destory_env_done_val){
+ /* ��������libsapp_destroy_env() �˳�����, ���澯 */
+ if(SAPP_DESTROY_DONE_FLAG == g_sapp_destory_env_done_state){
return;
}
diff --git a/src/sapp_dev/sapp_plug.c b/src/sapp_dev/sapp_plug.c
index 6f0e243..b323eee 100644
--- a/src/sapp_dev/sapp_plug.c
+++ b/src/sapp_dev/sapp_plug.c
@@ -27,11 +27,13 @@ int dpdk_init(int argc, char **argv);
/*
��Щ�������ܷ���sapp_global_val, �����ж�destroy����״̬��, destroy��������Ҫfree sapp_global_val������!
- 0:do nothing; 1:just doing; SAPP_DESTROY_DONE_FLAG:done;
+ 0:init or done; >= 1:just doing in any thread;
*/
-volatile unsigned long g_sapp_destory_env_done_val;
-static volatile unsigned long g_destory_env_per_thread_done[MAX_THREAD_NUM];
+volatile unsigned long g_sapp_destory_env_running_state;
+volatile unsigned long g_sapp_destory_env_done_state;
+
+static volatile unsigned long g_destory_env_per_thread_running_state[MAX_THREAD_NUM];
static void signal_user_handler(int signo)
@@ -95,8 +97,9 @@ int libsapp_setup_env(int argc, char *argv[])
{
int ret;
- MESA_ATOMIC_SET(g_sapp_destory_env_done_val, 0);
- memset((void *)g_destory_env_per_thread_done, 0, sizeof(g_destory_env_per_thread_done));
+ MESA_ATOMIC_SET(g_sapp_destory_env_running_state, 0);
+ MESA_ATOMIC_SET(g_sapp_destory_env_done_state, 0);
+ memset((void *)g_destory_env_per_thread_running_state, 0, sizeof(g_destory_env_per_thread_running_state));
sapp_gval_init();
sapp_set_current_state(SAPP_STATE_JUST_START);
@@ -175,18 +178,17 @@ static void wait_for_all_io_threads(void)
void libsapp_destroy_env_per_thread(int tseq)
{
- if(MESA_ATOMIC_INC(g_destory_env_per_thread_done[tseq]) != 1){
- /* INC����1, ˵��ԭ���϶�����0, ˵��������һ���߳�������destroy����, �����ȴ�, ֱ������Ϊֹ */
- while(MESA_ATOMIC_READ(g_destory_env_per_thread_done[tseq]) != SAPP_DESTROY_DONE_FLAG){
- sapp_usleep(100);
+ if(MESA_ATOMIC_INC(g_destory_env_per_thread_running_state[tseq]) != 1){
+ /* ��ʼ��ʱ��0, INC����1, ˵����������һ���߳�������destroy����, �����ȴ�, ֱ������Ϊֹ */
+ MESA_ATOMIC_DEC(g_destory_env_per_thread_running_state[tseq]);
+ while(MESA_ATOMIC_READ(g_destory_env_per_thread_running_state[tseq]) != 0){
+ sapp_usleep(1000);
}
return;
- }else{
- MESA_ATOMIC_SET(g_destory_env_per_thread_done[tseq], 1);
}
packet_io_clean_thread_context(tseq);
- MESA_ATOMIC_SET(g_destory_env_per_thread_done[tseq], SAPP_DESTROY_DONE_FLAG);
+ MESA_ATOMIC_DEC(g_destory_env_per_thread_running_state[tseq]);
}
@@ -197,20 +199,20 @@ void libsapp_destroy_env(void)
int exit_process = 0;
/*
- һ���������: sapp -d������Ϻ�, ���Զ�����libsapp_destroy_env(),
+ ע��! һ���������:
+ sapp -d������Ϻ�, ���Զ�����libsapp_destroy_env(),
���Dz��Ҳ���ܻ����ⲿ��������libsapp_destroy_env(),
- �����������, ��double free��!!
- �˴�����������һ���Ⱥ��߼�˳��.
+ �������ͬ������, ��double free��!!
+ �˴������ü�������һ���Ⱥ��߼�˳��.
*/
- if(MESA_ATOMIC_INC(g_sapp_destory_env_done_val) != 1){
- /* INC����1, ˵��ԭ���϶�����0, ˵��������һ���߳�������destroy����, �����ȴ�, ֱ������Ϊֹ */
- while(MESA_ATOMIC_READ(g_sapp_destory_env_done_val) != SAPP_DESTROY_DONE_FLAG){
- sapp_usleep(100);
+ if(MESA_ATOMIC_INC(g_sapp_destory_env_running_state) != 1){
+ /* ��ʼ��ʱ��0, INC����1, ˵����������һ���߳�������destroy����, �����ȴ�, ֱ������Ϊֹ */
+ MESA_ATOMIC_DEC(g_sapp_destory_env_running_state);
+ while(MESA_ATOMIC_READ(g_sapp_destory_env_running_state) != 0){
+ sapp_usleep(1000);
}
return;
- }else{
- MESA_ATOMIC_SET(g_sapp_destory_env_done_val, 1);
}
if(NULL == sapp_global_val){
@@ -227,8 +229,10 @@ void libsapp_destroy_env(void)
wait_for_all_io_threads();
packet_io_exit();
- MESA_ATOMIC_SET(g_sapp_destory_env_done_val, SAPP_DESTROY_DONE_FLAG);
+ /* ������Դ��free��, ��ȥ���ü��� */
+ MESA_ATOMIC_DEC(g_sapp_destory_env_running_state);
+ MESA_ATOMIC_SET(g_sapp_destory_env_done_state, SAPP_DESTROY_DONE_FLAG);
if(exit_process){
exit(0);
}
diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c
index d5529dd..8a30403 100644
--- a/test/test_app_sapp.c
+++ b/test/test_app_sapp.c
@@ -3234,6 +3234,7 @@ char IP_FRAG_ENTRY( struct streaminfo *stream,unsigned char routedir,int thread_
return APP_STATE_GIVEME;
}
+
enum anti_flood_stat_type{
ANTI_FLOOD_TCP_SYN = 0,
ANTI_FLOOD_UDP_DNS,
@@ -3414,8 +3415,25 @@ static void __fake_project_free_cb(int thread_seq, void *project_req_value)
;
}
+static void *test_app_thread(void *arg)
+{
+ while(1){
+ if((time(NULL) % 10) == 0){
+ printf("test thread: call libsapp_destroy_env()....\n");
+ libsapp_destroy_env();
+ printf("test thread: libsapp_destroy_env() done!\n");
+ exit(0);
+ }
+
+ sleep(1);
+ }
+
+ return NULL;
+}
+
int CHAR_INIT()
{
+ int i;
CHAR_CONFIG_INIT();
/* �������ڳ�ʼ��ʱ����ע��project */
@@ -3431,6 +3449,18 @@ int CHAR_INIT()
}
stream_bridge_register_data_free_cb(g_test_app_val.test_bridge_id, __stream_bridge_free_cb);
+
+ if((g_test_app_val.ivalue1 > 0)
+ && (strncasecmp("test sapp destroy", g_test_app_val.str_value1, strlen("test sapp destroy")) == 0)){
+ printf("\033[1;31;40m Warning: etc/test_app.conf : enable 'test sapp destroy', maybe exit after N seconds....\033[0m\n ");
+ pthread_t pid;
+
+ for( i = 0; i < g_test_app_val.ivalue1; i++){
+ pthread_create(&pid, NULL, test_app_thread, NULL);
+ pthread_detach(pid);
+ }
+ }
+
return 1;
}