diff options
| author | yangwei <[email protected]> | 2023-07-27 00:07:32 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2023-07-27 00:07:32 +0800 |
| commit | fa9583e3530f4c4f757af668a5870723f612ab56 (patch) | |
| tree | 3bbbceb3bc05e4350b3d51faa3caa7da516b75f9 | |
| parent | 76f935b49f366c18cc509d1133a63ad16eace722 (diff) | |
🐞 fix(tsg_statistic_thread): detach统计线程,根据sapp运行状态决定是否退出
| -rw-r--r-- | src/tsg_statistic.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index 2ca8c39..a713c43 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -136,6 +136,7 @@ int tsg_set_policy_flow(const struct streaminfo *a_stream, struct maat_rule *p_r static void *tsg_statistic_thread(void *arg) { + pthread_detach(pthread_self()); fieldstat_instance_start(g_tsg_statis_para.statistic_handle); while(g_tsg_statis_para.thread_alive) @@ -144,6 +145,15 @@ static void *tsg_statistic_thread(void *arg) long long total_value=0; int value_len=sizeof(long long); + + int state=0; + int state_len=sizeof(int); + sapp_get_platform_opt(SPO_CURRENT_STATE, (void *)&state, &state_len); + if(state > SAPP_STATE_PROCESSING) + { + break; + } + value=0; total_value=0; sapp_get_platform_opt(SPO_TCP_STREAM_ESTAB, (void *)&value, &value_len); @@ -209,7 +219,7 @@ static void *tsg_statistic_thread(void *arg) sleep(g_tsg_statis_para.cycle); } - + pthread_exit(NULL); return NULL; } @@ -477,10 +487,8 @@ int tsg_metric_init(const char *conffile, void *logger) void tsg_metric_destroy(void) { - pthread_cancel(g_tsg_statis_para.stat_thread_id); g_tsg_statis_para.thread_alive = 0; - sleep(g_tsg_statis_para.cycle); + sleep(g_tsg_statis_para.cycle+1); fieldstat_instance_free(g_tsg_statis_para.statistic_handle); - return; } |
