diff options
| author | lijia <[email protected]> | 2021-11-10 12:55:27 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2021-11-10 12:55:27 +0800 |
| commit | bb08abbde07e2c5d322f5040ec67b42c992d176e (patch) | |
| tree | d5e841585797637b1c706774434fb929fd09475b /src/sapp_dev | |
| parent | 571718c4da275ef2e8e6e2b3fef847b94dbe5d59 (diff) | |
修复多个流程同时调用libsapp_destroy_env()时, 可能会阻塞的问题.v4.2.67
Diffstat (limited to 'src/sapp_dev')
| -rw-r--r-- | src/sapp_dev/sapp_init.c | 7 | ||||
| -rw-r--r-- | src/sapp_dev/sapp_plug.c | 48 |
2 files changed, 31 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); } |
