]> Kevux Git Server - controller/commitdiff
Update: Relocate the clean up thread thread cancel state.
authorKevin Day <Kevin@kevux.org>
Tue, 12 Aug 2025 02:51:13 +0000 (21:51 -0500)
committerKevin Day <Kevin@kevux.org>
Tue, 12 Aug 2025 02:51:13 +0000 (21:51 -0500)
Relocate the cancel state changes to outside both waits.

I do not like how this is now happening with a thread lock in place.
I will need to do further research and possibly further changes to better handle this.

For now, this is necessary so that when I send an interrupt signal that the clean up thread will cancel properly.

sources/c/program/controller/main/thread/cleanup.c

index f0d8400fa8c678db8517279c921e4ca8f40618a9..8952112a3e33e55ba242de83c8f4a99219d119a7 100644 (file)
@@ -22,6 +22,9 @@ extern "C" {
 
     while (controller_thread_enable_get(&main->thread) == controller_thread_enable_e) {
 
+      // Allow thread to be interrupted and auto-cancelled while sleeping.
+      f_thread_cancel_state_set(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
+
       controller_time_now(
         main->setting.flag & controller_main_flag_simulate_d
           ? controller_thread_cleanup_interval_short_d
@@ -41,15 +44,12 @@ extern "C" {
       else {
         status = F_okay;
 
-        // Allow thread to be interrupted and auto-cancelled while sleeping.
-        f_thread_cancel_state_set(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
-
         f_time_sleep_spec(delay, 0);
-
-        // Prevent thread from being interrupted and auto-cancelled.
-        f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0);
       }
 
+      // Prevent thread from being interrupted and auto-cancelled.
+      f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0);
+
       // Reaping child processes is not critical, so don't care if the reap flag cannot be unset.
       if (!controller_thread_signal_get(&main->thread) && F_status_is_error_not(status)) {
         memset((void *) &signal_data, 0, sizeof(siginfo_t));