]> Kevux Git Server - fll/commitdiff
Cleanup: Some style clean ups.
authorKevin Day <Kevin@kevux.org>
Sun, 14 Jul 2024 04:50:53 +0000 (23:50 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 14 Jul 2024 04:50:53 +0000 (23:50 -0500)
I did not seek out anything to clean up.
This just cleans up some code that I happened to be looking at.

level_3/controller/c/thread/private-thread.c
level_3/controller/c/thread/private-thread_control.c
level_3/controller/c/thread/private-thread_entry.c
level_3/controller/c/thread/private-thread_process.c

index e06ee5708e4a6dab68d1717497ab44b7c599c7e4..a88747ff9d56f1a10f76476d9510950e5d47618a 100644 (file)
@@ -327,10 +327,6 @@ extern "C" {
 
     controller_thread_delete_simple(&thread);
 
-    if (F_status_is_error(status)) {
-      return F_status_set_error(F_failure);
-    }
-
     if (F_status_set_fine(status) == F_interrupt) {
       controller_print_signal_received(main, thread.signal);
 
@@ -341,7 +337,7 @@ extern "C" {
       return F_status_set_error(F_interrupt);
     }
 
-    return F_none;
+    return F_status_is_error(status) ? F_status_set_error(F_failure) : F_none;
   }
 #endif // _di_controller_thread_main_
 
index 3f0142fff79bfd420f8f17bd0c3dc5025405fde5..d20c05cae39cb2a5d5e901feccdc3bc3bc091b61 100644 (file)
@@ -15,7 +15,7 @@ extern "C" {
 
     f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0);
 
-    const controller_global_t *global = (controller_global_t *) arguments;
+    const controller_global_t * const global = (controller_global_t *) arguments;
 
     if (global->thread->enabled != controller_thread_enabled_e) return 0;
 
index e204f3f7a54e8459b23bc458711909ece0e769c9..a89c1c42de24d95304de22695ddd4891b90ddefb 100644 (file)
@@ -141,11 +141,10 @@ extern "C" {
 
       // According to the manpages, pthread_exit() calls exit(0), which is not good because a non-zero exit code may be returned.
       if (main->child) exit(main->child);
-
-      return 0;
     }
-
-    f_thread_condition_signal_all(&entry->global->thread->lock.alert_condition);
+    else {
+      f_thread_condition_signal_all(&entry->global->thread->lock.alert_condition);
+    }
 
     return 0;
   }
@@ -256,13 +255,12 @@ extern "C" {
       controller_thread_delete_simple(entry->global->thread);
       controller_setting_delete_simple(entry->global->setting);
       controller_main_delete(entry->global->main);
-
-      return 0;
     }
+    else {
+      controller_thread_process_exit_force_set_disable(entry->global);
 
-    controller_thread_process_exit_force_set_disable(entry->global);
-
-    f_thread_condition_signal_all(&entry->global->thread->lock.alert_condition);
+      f_thread_condition_signal_all(&entry->global->thread->lock.alert_condition);
+    }
 
     return 0;
   }
index 51954ab44766232dc3fbae85bb318f1ba58be848..0941c6d6bde82c9c492e1d866a715484f608f4f6 100644 (file)
@@ -15,11 +15,7 @@ extern "C" {
 #ifndef _di_controller_thread_process_
   void controller_thread_process(const bool is_normal, controller_process_t * const process) {
 
-    {
-      controller_thread_t *thread = (controller_thread_t *) process->main_thread;
-
-      if (!controller_thread_is_enabled(is_normal, thread)) return;
-    }
+    if (!controller_thread_is_enabled(is_normal, (controller_thread_t *) process->main_thread)) return;
 
     const f_status_t status = controller_rule_process_do(controller_process_option_asynchronous_d, process);
 
@@ -28,12 +24,10 @@ extern "C" {
       // A forked child process should deallocate memory on exit.
       // It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below.
       // Deallocate as much as possible.
-      controller_main_t *main = (controller_main_t *) process->main_data;
-      controller_setting_t *setting = (controller_setting_t *) process->main_setting;
-      controller_thread_t *thread = (controller_thread_t *) process->main_thread;
+      controller_main_t * const main = (controller_main_t *) process->main_data;
 
-      controller_thread_delete_simple(thread);
-      controller_setting_delete_simple(setting);
+      controller_thread_delete_simple((controller_thread_t *) process->main_thread);
+      controller_setting_delete_simple((controller_setting_t *) process->main_setting);
       controller_main_delete(main);
 
       // According to the manpages, pthread_exit() calls exit(0), which is not good because a non-zero exit code may be returned.
@@ -58,20 +52,13 @@ extern "C" {
 
     struct timespec time;
 
-    controller_entry_t *entry = 0;
+    controller_entry_t * const entry = is_normal ? &global->setting->entry : &global->setting->exit;
     controller_process_t *process = 0;
 
     f_array_length_t i = 0;
     f_array_length_t j = 0;
     pid_t pid = 0;
 
-    if (is_normal) {
-      entry = &global->setting->entry;
-    }
-    else {
-      entry = &global->setting->exit;
-    }
-
     // A simple but inaccurate interval counter (expect this to be replaced in the future).
     const f_number_unsigned_t interval_nanoseconds = entry->timeout_exit < 1000 ? (entry->timeout_exit < 100 ? 5000000 : 100000000) : 500000000;
     const f_number_unsigned_t interval_milliseconds = entry->timeout_exit < 1000 ? (entry->timeout_exit < 100 ? 5 : 100) : 500;
@@ -194,9 +181,7 @@ extern "C" {
         process = global->thread->processs.array[i];
 
         // Do not wait for processes, when not performing "execute" during exit.
-        if (process->type == controller_process_type_exit_e && global->thread->enabled != controller_thread_enabled_exit_execute_e) {
-          continue;
-        }
+        if (process->type == controller_process_type_exit_e && global->thread->enabled != controller_thread_enabled_exit_execute_e) continue;
 
         for (j = 0; j < process->childs.used && lapsed < entry->timeout_exit; ++j) {
 
@@ -345,9 +330,7 @@ extern "C" {
 #ifndef _di_controller_thread_process_exit_
   void controller_thread_process_exit(controller_global_t * const global) {
 
-    if (global->thread->enabled != controller_thread_enabled_exit_e) {
-      return;
-    }
+    if (global->thread->enabled != controller_thread_enabled_exit_e) return;
 
     if (global->setting->ready == controller_setting_ready_done_e) {