From: Kevin Day Date: Fri, 15 Aug 2025 02:45:41 +0000 (-0500) Subject: Update: Additional lock tweaks. X-Git-Tag: 0.7.3~31 X-Git-Url: https://www.git.kevux.org/?a=commitdiff_plain;h=42a6980853bc863dc7afd31a34a6cd31a70c8407;p=controller Update: Additional lock tweaks. I am thinking of doing some redesigning of the locking/unlocking processes after this commit. I may end up adding a new type to the FLL project to standardize a more complex structure. I believe I need to create a read/write lock pair with a mutex lock so that the mutex can be used to prep a lock for transitioning from a read to a write or a write to a read. I need to do some more extensive planning. --- diff --git a/sources/c/program/controller/main/common/define.h b/sources/c/program/controller/main/common/define.h index 2e69c07..01c75fc 100644 --- a/sources/c/program/controller/main/common/define.h +++ b/sources/c/program/controller/main/common/define.h @@ -37,6 +37,20 @@ extern "C" { #endif // _di_controller_allocation_d_ /** + * Controller lock check flags. + * + * controller_lock_check_flag_*_d: + * - no: Do not perform any checks; only return on success (or initial parameter errors before calling locks or waits). + * - yes: Perform all checks and return (error check and enabled/disable check). + * - error: Only perform error check and return. + */ +#ifndef _di_controller_lock_check_flag_d_ + #define controller_lock_check_flag_no_d 0x0 + #define controller_lock_check_flag_yes_d 0x1 + #define controller_lock_check_flag_error_d 0x2 +#endif // _di_controller_lock_check_flag_d_ + +/** * Controller lock defines. * * controller_lock_*_d: diff --git a/sources/c/program/controller/main/common/type/lock.c b/sources/c/program/controller/main/common/type/lock.c index a3a16cc..73e83aa 100644 --- a/sources/c/program/controller/main/common/type/lock.c +++ b/sources/c/program/controller/main/common/type/lock.c @@ -11,6 +11,7 @@ extern "C" { f_thread_mutex_delete(&lock->alert); f_thread_mutex_delete(&lock->cancel); + f_thread_mutex_delete(&lock->entry); f_thread_mutex_delete(&lock->print); f_thread_mutex_delete(&lock->reap); diff --git a/sources/c/program/controller/main/common/type/lock.h b/sources/c/program/controller/main/common/type/lock.h index 9d93c9a..d54ea3f 100644 --- a/sources/c/program/controller/main/common/type/lock.h +++ b/sources/c/program/controller/main/common/type/lock.h @@ -31,6 +31,7 @@ extern "C" { * - flag: A set of flags associated with the locks. * - alert: The alert mutex lock for waking up on alerts. * - cancel: The cancel mutex lock for locking the cancel operation. + * - entry: The entry mutex lock for entry reading (preventing entry and exit from overlapping). * - print: The print mutex lock. * - reap: The reap_condition mutex lock. * - enable: The enable r/w lock. @@ -46,6 +47,7 @@ extern "C" { f_thread_mutex_t alert; f_thread_mutex_t cancel; + f_thread_mutex_t entry; f_thread_mutex_t print; f_thread_mutex_t reap; @@ -64,6 +66,7 @@ extern "C" { f_thread_mutex_t_initialize, \ f_thread_mutex_t_initialize, \ f_thread_mutex_t_initialize, \ + f_thread_mutex_t_initialize, \ f_thread_lock_t_initialize, \ f_thread_lock_t_initialize, \ f_thread_lock_t_initialize, \ diff --git a/sources/c/program/controller/main/entry.c b/sources/c/program/controller/main/entry.c index 3978e19..eb2a589 100644 --- a/sources/c/program/controller/main/entry.c +++ b/sources/c/program/controller/main/entry.c @@ -9,6 +9,22 @@ extern "C" { if (!main) return F_status_set_error(F_parameter); + f_status_t status = controller_lock_mutex_standard(is_entry, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.entry); + if (F_status_is_error(status)) return status; + + status = controller_entry_read_do(main, is_entry); + + f_thread_mutex_unlock(&main->thread.lock.entry); + + return status; + } +#endif // _di_controller_entry_read_ + +#ifndef _di_controller_entry_read_do_ + f_status_t controller_entry_read_do(controller_t * const main, const uint8_t is_entry) { + + if (!main) return F_status_set_error(F_parameter); + controller_entry_t * const entry = is_entry ? &main->process.entry : &main->process.exit; controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_entry, main); @@ -336,7 +352,7 @@ extern "C" { return entry->status; } -#endif // _di_controller_entry_read_ +#endif // _di_controller_entry_read_do_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/program/controller/main/entry.h b/sources/c/program/controller/main/entry.h index 4515958..67a2a2f 100644 --- a/sources/c/program/controller/main/entry.h +++ b/sources/c/program/controller/main/entry.h @@ -17,6 +17,34 @@ extern "C" { #endif /** + * Read the entry, extracting all lists, with locking. + * + * This wraps controller_entry_read_do() with a mutex lock to prevent double execution. + * + * @param main + * The main program data. + * + * This does not alter main.setting.state.status. + * + * Must not be NULL. + * @param is_entry + * If TRUE, then this operates as an Entry. + * If FALSE, then this operates as an Exit. + * + * @return + * Success from controller_entry_read_do(). + * + * Errors (with error bit) from: controller_entry_read_do(). + * Errors (with error bit) from: controller_lock_mutex_standard(). + * + * @see controller_entry_read_do() + * @see controller_lock_mutex_standard() + */ +#ifndef _di_controller_entry_read_ + extern f_status_t controller_entry_read(controller_t * const main, const uint8_t is_entry); +#endif // _di_controller_entry_read_ + +/** * Read the entry, extracting all lists. * * @param main @@ -63,9 +91,9 @@ extern "C" { * @see f_fss_apply_delimit() * @see fll_fss_basic_list_read() */ -#ifndef _di_controller_entry_read_ - extern f_status_t controller_entry_read(controller_t * const main, const uint8_t is_entry); -#endif // _di_controller_entry_read_ +#ifndef _di_controller_entry_read_do_ + extern f_status_t controller_entry_read_do(controller_t * const main, const uint8_t is_entry); +#endif // _di_controller_entry_read_do_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/program/controller/main/entry/process.c b/sources/c/program/controller/main/entry/process.c index ab13094..2e99aa0 100644 --- a/sources/c/program/controller/main/entry/process.c +++ b/sources/c/program/controller/main/entry/process.c @@ -186,7 +186,7 @@ extern "C" { break; } else if (entry_action->type == controller_entry_action_type_consider_e || controller_entry_action_type_is_rule(entry_action->type)) { - status_lock = controller_lock_write_standard(is_entry, F_true, &main->thread, &main->thread.lock.rule); + status_lock = controller_lock_write_standard(is_entry, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.rule); if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); @@ -214,7 +214,7 @@ extern "C" { id_rule_name[entry_action->parameters.array[0].used] = f_path_separator_s.string[0]; id_rule_name[id_rule_length] = 0; - status_lock = controller_lock_read_standard(is_entry, F_true, &main->thread, &main->thread.lock.rule); + status_lock = controller_lock_read_standard(is_entry, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.rule); if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_true); @@ -251,7 +251,7 @@ extern "C" { memcpy(cache_name_item, cache->action.name_item.string, sizeof(f_char_t) * cache->action.name_item.used); memcpy(cache_name_file, cache->action.name_file.string, sizeof(f_char_t) * cache->action.name_file.used); - status_lock = controller_lock_write_standard(is_entry, F_true, &main->thread, &main->thread.lock.rule); + status_lock = controller_lock_write_standard(is_entry, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.rule); if (status_lock == F_okay) { status = controller_rule_read(main, cache, is_entry, alias_rule, entry, &main->process.rules.array[main->process.rules.used]); diff --git a/sources/c/program/controller/main/instance/prepare.c b/sources/c/program/controller/main/instance/prepare.c index ffa0012..ceb9f93 100644 --- a/sources/c/program/controller/main/instance/prepare.c +++ b/sources/c/program/controller/main/instance/prepare.c @@ -14,7 +14,7 @@ extern "C" { if (controller_instance_find(action, alias, main->thread.instances, id) == F_false) { f_thread_unlock(&main->thread.lock.instance); - status = controller_lock_write_standard(is_normal, F_true, &main->thread, &main->thread.lock.instance); + status = controller_lock_write_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.instance); if (status != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status), F_false); @@ -35,7 +35,7 @@ extern "C" { controller_instance_t * const instance = F_status_is_error_not(status) ? main->thread.instances.array[main->thread.instances.used] : 0; if (status == F_okay) { - status = controller_lock_write_standard(is_normal, F_true, &main->thread, &instance->lock); + status = controller_lock_write_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance->lock); } if (F_status_is_error(status)) { @@ -65,7 +65,7 @@ extern "C" { } // The read lock must be restored on return. - const f_status_t status_restore = F_status_is_error(controller_lock_read_standard(is_normal, F_false, &main->thread, &main->thread.lock.instance)) + const f_status_t status_restore = F_status_is_error(controller_lock_read_standard(is_normal, controller_lock_check_flag_no_d, &main->thread, &main->thread.lock.instance)) ? F_status_set_error(F_lock_read) : F_okay; diff --git a/sources/c/program/controller/main/lock.c b/sources/c/program/controller/main/lock.c index 93c5604..7b50c77 100644 --- a/sources/c/program/controller/main/lock.c +++ b/sources/c/program/controller/main/lock.c @@ -15,53 +15,61 @@ extern "C" { status = f_thread_mutex_create(0, &lock->cancel); if (F_status_is_error_not(status)) { - status = f_thread_mutex_create(0, &lock->print); + status = f_thread_mutex_create(0, &lock->entry); if (F_status_is_error_not(status)) { - status = f_thread_mutex_create(0, &lock->reap); + status = f_thread_mutex_create(0, &lock->print); if (F_status_is_error_not(status)) { - status = f_thread_lock_create(0, &lock->enable); + status = f_thread_mutex_create(0, &lock->reap); if (F_status_is_error_not(status)) { - status = f_thread_lock_create(0, &lock->instance); + status = f_thread_lock_create(0, &lock->enable); if (F_status_is_error_not(status)) { - status = f_thread_lock_create(0, &lock->rule); + status = f_thread_lock_create(0, &lock->instance); if (F_status_is_error_not(status)) { - status = f_thread_condition_create(0, &lock->alert_condition); + status = f_thread_lock_create(0, &lock->rule); if (F_status_is_error_not(status)) { - status = f_thread_condition_create(0, &lock->reap_condition); + status = f_thread_condition_create(0, &lock->alert_condition); + + if (F_status_is_error_not(status)) { + status = f_thread_condition_create(0, &lock->reap_condition); + + if (F_status_is_error(status)) { + f_thread_condition_delete(&lock->alert_condition); + } + } if (F_status_is_error(status)) { - f_thread_condition_delete(&lock->alert_condition); + f_thread_lock_delete(&lock->rule); } } if (F_status_is_error(status)) { - f_thread_lock_delete(&lock->rule); + f_thread_lock_delete(&lock->instance); } } if (F_status_is_error(status)) { - f_thread_lock_delete(&lock->instance); + f_thread_lock_delete(&lock->enable); } } if (F_status_is_error(status)) { - f_thread_lock_delete(&lock->enable); + f_thread_mutex_delete(&lock->reap); } } if (F_status_is_error(status)) { - f_thread_mutex_delete(&lock->reap); + f_thread_mutex_delete(&lock->print); } } if (F_status_is_error(status)) { - f_thread_mutex_delete(&lock->print); + f_thread_mutex_delete(&lock->entry); } } @@ -99,7 +107,7 @@ extern "C" { if (status == F_time) { if (check) { - if (check == 0x2) { + if (check == controller_lock_check_flag_error_d) { if (F_status_is_error(status)) return status; } else if (!controller_thread_enable_is(thread, is_normal)) return F_status_set_error(F_interrupt); @@ -126,7 +134,7 @@ extern "C" { if (!instance) return F_status_set_error(F_parameter); - return controller_lock_mutex_standard(instance->type != controller_instance_type_exit_e, F_true, &instance->main->thread, mutex); + return controller_lock_mutex_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_yes_d, &instance->main->thread, mutex); } #endif // _di_controller_lock_mutex_instance_ @@ -147,7 +155,7 @@ extern "C" { if (status == F_time) { if (check) { - if (check == 0x2) { + if (check == controller_lock_check_flag_error_d) { if (F_status_is_error(status)) return status; } else if (!controller_thread_enable_is(thread, is_normal)) return F_status_set_error(F_interrupt); @@ -174,7 +182,7 @@ extern "C" { if (!instance || !instance->main) return F_status_set_error(F_parameter); - return controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_true, &instance->main->thread, lock); + return controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_yes_d, &instance->main->thread, lock); } #endif // _di_controller_lock_read_instance_ @@ -193,7 +201,7 @@ extern "C" { if (status == F_time) { if (check) { - if (check == 0x2) { + if (check == controller_lock_check_flag_error_d) { if (F_status_is_error(status)) return status; } else if (!controller_thread_enable_is(thread, is_normal)) return F_status_set_error(F_interrupt); @@ -220,7 +228,7 @@ extern "C" { if (!instance) return F_status_set_error(F_parameter); - return controller_lock_write_standard(instance->type != controller_instance_type_exit_e, F_true, &instance->main->thread, lock); + return controller_lock_write_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_yes_d, &instance->main->thread, lock); } #endif // _di_controller_lock_write_instance_ diff --git a/sources/c/program/controller/main/lock.h b/sources/c/program/controller/main/lock.h index 4c33330..c15481e 100644 --- a/sources/c/program/controller/main/lock.h +++ b/sources/c/program/controller/main/lock.h @@ -45,9 +45,9 @@ extern "C" { * Given a mutex lock, periodically check to see if main thread is disabled while waiting. * * @param is_normal - * If TRUE, then perform as if this operates during a normal operation (Entry and Control). - * If FALSE, then perform as if this operates during a an Exit operation. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param check * If TRUE, then check if the state is enabled and if it is not then abort. * If FALSE, then do not check if the state is enabled and keep looping. @@ -86,9 +86,9 @@ extern "C" { * Given a mutex lock, periodically check to see if main thread is disabled while waiting. * * @param is_normal - * If TRUE, then perform as if this operates during a normal operation (Entry and Control). - * If FALSE, then perform as if this operates during a an Exit operation. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param check * If TRUE, then check if the state is enabled and if it is not then abort. * If FALSE, then do not check if the state is enabled and keep looping. @@ -148,9 +148,9 @@ extern "C" { * If TRUE, then perform as if this operates during a normal operation (Entry and Control). * If FALSE, then perform as if this operates during a an Exit operation. * @param check - * If TRUE, then check if the state is enabled and if it is not then abort. - * If FALSE, then do not check if the state is enabled and keep looping. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param seconds * The seconds to add to current time. * @param nanoseconds @@ -189,9 +189,9 @@ extern "C" { * If TRUE, then perform as if this operates during a normal operation (Entry and Control). * If FALSE, then perform as if this operates during a an Exit operation. * @param check - * If TRUE, then check if the state is enabled and if it is not then abort. - * If FALSE, then do not check if the state is enabled and keep looping. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param thread * The thread data used to determine if the main thread is disabled or not. * @@ -248,9 +248,9 @@ extern "C" { * If TRUE, then perform as if this operates during a normal operation (Entry and Control). * If FALSE, then perform as if this operates during a an Exit operation. * @param check - * If TRUE, then check if the state is enabled and if it is not then abort. - * If FALSE, then do not check if the state is enabled and keep looping. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param seconds * The seconds to add to current time. * @param nanoseconds @@ -289,9 +289,9 @@ extern "C" { * If TRUE, then perform as if this operates during a normal operation (Entry and Control). * If FALSE, then perform as if this operates during a an Exit operation. * @param check - * If TRUE, then check if the state is enabled and if it is not then abort. - * If FALSE, then do not check if the state is enabled and keep looping. - * IF 0x2, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * IF controller_lock_check_flag_error_d, then this is is also TRUE, but it does not call controller_thread_enable_is() and returns on any lock error. + * If controller_lock_check_flag_no_d, then do not check if the state is enabled and keep looping. + * If controller_lock_check_flag_yes_d, then check if the state is enabled and if it is not then abort. * @param thread * The thread data used to determine if the main thread is disabled or not. * diff --git a/sources/c/program/controller/main/rule/execute.c b/sources/c/program/controller/main/rule/execute.c index 94bd07d..69b3b21 100644 --- a/sources/c/program/controller/main/rule/execute.c +++ b/sources/c/program/controller/main/rule/execute.c @@ -410,7 +410,7 @@ extern "C" { success = F_false; if (F_status_set_fine(status) == F_lock_read) { - status = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + status = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); if (status != F_okay) return F_status_set_error(F_lock_read); status = F_status_set_error(F_lock); @@ -440,7 +440,7 @@ extern "C" { f_execute_result_t result = f_execute_result_t_initialize; // @fixme Lock the instance.childs.used with write access. (active should already have a read lock) - //status = controller_lock_write_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + //status = controller_lock_write_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); //if (status != F_okay) return F_status_set_error(F_lock_read); status = f_memory_array_increase(controller_allocation_small_d, sizeof(pid_t), (void **) &instance->childs.array, &instance->childs.used, &instance->childs.size); @@ -491,7 +491,7 @@ extern "C" { if (F_status_is_error(status_lock)) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &instance->main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &instance->main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); @@ -510,7 +510,7 @@ extern "C" { // Try again, after the first interrupt. if (F_status_set_fine(status_lock) == F_interrupt) { - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &instance->main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &instance->main->thread, &instance->lock); } if (status_lock != F_okay) { @@ -606,7 +606,7 @@ extern "C" { f_execute_result_t result = f_execute_result_t_initialize; // @fixme Lock the instance.childs.used with write access. (active should already have a read lock) - //status = controller_lock_write_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + //status = controller_lock_write_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); //if (status != F_okay) return F_status_set_error(F_lock_read); status = f_memory_array_increase(controller_allocation_small_d, sizeof(pid_t), (void **) &instance->childs.array, &instance->childs.used, &instance->childs.size); @@ -685,7 +685,7 @@ extern "C" { if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &instance->main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &instance->main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); @@ -710,7 +710,7 @@ extern "C" { if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &instance->main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &instance->main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); diff --git a/sources/c/program/controller/main/rule/instance.c b/sources/c/program/controller/main/rule/instance.c index 717185f..945b632 100644 --- a/sources/c/program/controller/main/rule/instance.c +++ b/sources/c/program/controller/main/rule/instance.c @@ -407,7 +407,7 @@ extern "C" { if (F_status_is_error(status_lock)) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); @@ -428,7 +428,7 @@ extern "C" { // Remove the write lock and restore the read lock. f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); @@ -459,7 +459,7 @@ extern "C" { if (F_status_is_error(status_lock)) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_true); - status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, F_false, &main->thread, &instance->lock); + status_lock = controller_lock_read_standard(instance->type != controller_instance_type_exit_e, controller_lock_check_flag_no_d, &main->thread, &instance->lock); if (status_lock != F_okay) return F_status_set_error(F_lock_read); return F_status_set_error(F_lock); @@ -475,7 +475,7 @@ extern "C" { if (!main || !cache) return F_status_set_error(F_parameter); if (!controller_thread_is_enabled_instance_type(&main->thread, type)) return F_status_set_error(F_interrupt); - f_status_t status = controller_lock_read_standard(type != controller_instance_type_exit_e, F_true, &main->thread, &main->thread.lock.instance); + f_status_t status = controller_lock_read_standard(type != controller_instance_type_exit_e, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.instance); if (status != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status), F_true); @@ -497,7 +497,7 @@ extern "C" { controller_instance_t * const instance = main->thread.instances.array[at]; - status = controller_lock_read_standard(type != controller_instance_type_exit_e, F_true, &main->thread, &instance->active); + status = controller_lock_read_standard(type != controller_instance_type_exit_e, controller_lock_check_flag_yes_d, &main->thread, &instance->active); if (status != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status), F_true); diff --git a/sources/c/program/controller/main/rule/wait.c b/sources/c/program/controller/main/rule/wait.c index 701e0d1..4cb2d68 100644 --- a/sources/c/program/controller/main/rule/wait.c +++ b/sources/c/program/controller/main/rule/wait.c @@ -9,7 +9,7 @@ extern "C" { if (!main) return F_status_set_error(F_parameter); - f_status_t status_lock = controller_lock_read_standard(is_normal, F_false, &main->thread, &main->thread.lock.instance); + f_status_t status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_no_d, &main->thread, &main->thread.lock.instance); if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_true); @@ -45,7 +45,7 @@ extern "C" { if (!controller_thread_enable_is(&main->thread, is_normal)) break; // Re-establish instance read lock to wait for or protect from the cleanup thread while checking the read instance. - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &main->thread.lock.instance); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &main->thread.lock.instance); if (status_lock != F_okay) break; if (!instance_list[i]) { @@ -54,7 +54,7 @@ extern "C" { continue; } - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &instance_list[i]->active); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->active); if (status_lock != F_okay) { f_thread_unlock(&main->thread.lock.instance); @@ -65,7 +65,7 @@ extern "C" { // Once the active lock is obtained, then the main instance read lock can be safely released. f_thread_unlock(&main->thread.lock.instance); - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &instance_list[i]->lock); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->lock); if (status_lock != F_okay) { f_thread_unlock(&instance_list[i]->active); @@ -87,7 +87,7 @@ extern "C" { if (instance_list[i]->state == controller_instance_state_done_e) { f_thread_unlock(&instance_list[i]->lock); - status_lock = controller_lock_write_standard(is_normal, F_true, &main->thread, &instance_list[i]->lock); + status_lock = controller_lock_write_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->lock); if (status_lock != F_okay) { controller_print_error_lock_critical(&main->program.error, F_status_set_fine(status_lock), F_false); @@ -109,7 +109,7 @@ extern "C" { f_thread_condition_signal_all(&instance_list[i]->wait_condition); } - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &instance_list[i]->active); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->active); if (status_lock != F_okay) { f_thread_unlock(&instance_list[i]->lock); @@ -120,7 +120,7 @@ extern "C" { f_thread_unlock(&instance_list[i]->lock); - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &instance_list[i]->lock); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->lock); if (status_lock != F_okay) break; } @@ -157,7 +157,7 @@ extern "C" { break; } - status_lock = controller_lock_read_standard(is_normal, F_true, &main->thread, &instance_list[i]->lock); + status_lock = controller_lock_read_standard(is_normal, controller_lock_check_flag_yes_d, &main->thread, &instance_list[i]->lock); if (status_lock != F_okay) { f_thread_unlock(&instance_list[i]->active); diff --git a/sources/c/program/controller/main/thread/instance.c b/sources/c/program/controller/main/thread/instance.c index df4ab6e..1753686 100644 --- a/sources/c/program/controller/main/thread/instance.c +++ b/sources/c/program/controller/main/thread/instance.c @@ -28,7 +28,7 @@ extern "C" { if (!main) return; - f_status_t status = controller_lock_mutex(is_normal, 0x2, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.cancel); + f_status_t status = controller_lock_mutex(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.cancel); if (F_status_is_error(status)) return; // Only cancel when enabled. @@ -54,7 +54,7 @@ extern "C" { time.tv_nsec = interval_nanoseconds; if (main->process.mode == controller_process_mode_helper_e && !(main->setting.flag & controller_main_flag_validate_d)) { - controller_lock_read(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); + controller_lock_read(is_normal, controller_lock_check_flag_no_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); for (i = 0; i < main->thread.instances.used; ++i) { @@ -116,7 +116,7 @@ extern "C" { return; } - status = controller_lock_read(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); + status = controller_lock_read(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); if (F_status_is_error(status)) { f_thread_mutex_unlock(&main->thread.lock.cancel); @@ -163,7 +163,7 @@ extern "C" { if (entry->timeout_exit && !(entry->flag & controller_entry_flag_timeout_exit_no_e)) { f_number_unsigned_t lapsed = 0; - controller_lock_read(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); + controller_lock_read(is_normal, controller_lock_check_flag_no_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); for (i = 0; i < main->thread.instances.used && lapsed < entry->timeout_exit; ++i) { @@ -228,7 +228,7 @@ extern "C" { f_thread_unlock(&main->thread.lock.instance); } - status = controller_lock_read(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); + status = controller_lock_read(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.lock.instance); if (F_status_is_error(status)) { f_thread_mutex_unlock(&main->thread.lock.cancel); @@ -240,7 +240,7 @@ extern "C" { if (!main->thread.instances.array[i]) continue; - status = controller_lock_read(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.instances.array[i]->active); + status = controller_lock_read(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &main->thread.instances.array[i]->active); if (F_status_is_error(status)) continue; instance = main->thread.instances.array[i]; @@ -287,7 +287,7 @@ extern "C" { f_signal_send(F_signal_kill, instance->childs.array[j]); } - status = controller_lock_write(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); + status = controller_lock_write(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); instance->childs.array[j] = 0; @@ -309,7 +309,7 @@ extern "C" { f_signal_send(F_signal_kill, pid); } - status = controller_lock_write(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); + status = controller_lock_write(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); f_file_remove(instance->path_pids.array[j]); instance->path_pids.array[j].used = 0; @@ -319,7 +319,7 @@ extern "C" { } // for } - status = controller_lock_write(is_normal, F_false, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); + status = controller_lock_write(is_normal, controller_lock_check_flag_error_d, controller_thread_timeout_cancel_seconds_d, controller_thread_timeout_cancel_nanoseconds_d, &main->thread, &instance->lock); if (F_status_is_error_not(status)) {