summaryrefslogtreecommitdiff
path: root/src/sapp_dev/sapp_plug.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sapp_dev/sapp_plug.c')
-rw-r--r--src/sapp_dev/sapp_plug.c48
1 files changed, 26 insertions, 22 deletions
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);
}