SIGINT for force exit, SIGSTOP for graceful exit

This commit is contained in:
luwenpeng
2024-08-27 19:37:00 +08:00
parent 79e70f7145
commit 7e04992aa0
3 changed files with 16 additions and 26 deletions

View File

@@ -42,7 +42,6 @@ struct stellar_thread
pthread_t tid;
uint16_t idx;
uint64_t is_runing;
uint64_t need_exit;
uint64_t last_free_expired_session_timestamp;
uint64_t last_free_expired_ip_frag_timestamp;
uint64_t last_merge_thread_stat_timestamp;
@@ -227,7 +226,7 @@ static void *work_thread(void *arg)
ATOMIC_SET(&thread->is_runing, 1);
CORE_LOG_FATAL("worker thread %d runing", thr_idx);
while (ATOMIC_READ(&thread->need_exit) == 0)
while (ATOMIC_READ(&runtime->need_exit) == 0)
{
/*
* We use the system's real time instead of monotonic time for the following reasons:
@@ -366,13 +365,15 @@ static void *work_thread(void *arg)
}
}
if (froce_session_expire_before_exit)
while (sess_stat->tcp_sess_used > 0 || sess_stat->udp_sess_used > 0)
{
free_expired_sessions(sess_mgr, UINT64_MAX, UINT64_MAX);
}
else
{
while (sess_stat->tcp_sess_used > 0 || sess_stat->udp_sess_used > 0)
// froce session expire
if (froce_session_expire_before_exit)
{
free_expired_sessions(sess_mgr, free_expired_session_batch, UINT64_MAX);
}
// wait session expire
else
{
now_ms = clock_get_real_time_ms();
free_expired_sessions(sess_mgr, free_expired_session_batch, now_ms);
@@ -605,11 +606,7 @@ void stellar_run(struct stellar *st)
// only available in dumpfile mode
if (packet_io_isbreak(runtime->packet_io))
{
for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
{
struct stellar_thread *thread = &runtime->threads[i];
ATOMIC_SET(&thread->need_exit, 1);
}
ATOMIC_SET(&runtime->need_exit, 1);
CORE_LOG_FATAL("notify worker thread to exit");
stellar_stat_output(runtime->stat); // flush stat
break;