From e9da3bfc7e297b069b07adfa1091239f23ec30e8 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 13 Jul 2024 23:50:53 -0500 Subject: [PATCH] Cleanup: Some style clean ups. 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 | 6 +---- .../controller/c/thread/private-thread_control.c | 2 +- level_3/controller/c/thread/private-thread_entry.c | 16 +++++------ .../controller/c/thread/private-thread_process.c | 31 +++++----------------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/level_3/controller/c/thread/private-thread.c b/level_3/controller/c/thread/private-thread.c index e06ee57..a88747f 100644 --- a/level_3/controller/c/thread/private-thread.c +++ b/level_3/controller/c/thread/private-thread.c @@ -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_ diff --git a/level_3/controller/c/thread/private-thread_control.c b/level_3/controller/c/thread/private-thread_control.c index 3f0142f..d20c05c 100644 --- a/level_3/controller/c/thread/private-thread_control.c +++ b/level_3/controller/c/thread/private-thread_control.c @@ -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; diff --git a/level_3/controller/c/thread/private-thread_entry.c b/level_3/controller/c/thread/private-thread_entry.c index e204f3f..a89c1c4 100644 --- a/level_3/controller/c/thread/private-thread_entry.c +++ b/level_3/controller/c/thread/private-thread_entry.c @@ -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; } diff --git a/level_3/controller/c/thread/private-thread_process.c b/level_3/controller/c/thread/private-thread_process.c index 51954ab..0941c6d 100644 --- a/level_3/controller/c/thread/private-thread_process.c +++ b/level_3/controller/c/thread/private-thread_process.c @@ -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) { -- 1.8.3.1