]> Kevux Git Server - controller/commitdiff
Update: Additional lock tweaks.
authorKevin Day <Kevin@kevux.org>
Fri, 15 Aug 2025 02:45:41 +0000 (21:45 -0500)
committerKevin Day <Kevin@kevux.org>
Fri, 15 Aug 2025 02:45:41 +0000 (21:45 -0500)
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.

13 files changed:
sources/c/program/controller/main/common/define.h
sources/c/program/controller/main/common/type/lock.c
sources/c/program/controller/main/common/type/lock.h
sources/c/program/controller/main/entry.c
sources/c/program/controller/main/entry.h
sources/c/program/controller/main/entry/process.c
sources/c/program/controller/main/instance/prepare.c
sources/c/program/controller/main/lock.c
sources/c/program/controller/main/lock.h
sources/c/program/controller/main/rule/execute.c
sources/c/program/controller/main/rule/instance.c
sources/c/program/controller/main/rule/wait.c
sources/c/program/controller/main/thread/instance.c

index 2e69c079f5a20b12562b0767f404e5035801cb48..01c75fcc4d7deeeb2117b4d07fe34bd2e8a12180 100644 (file)
@@ -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:
index a3a16cc0aee5c1b2fdbf7194b8370db2f030bc06..73e83aa4f2bd9502c1cafc8e27f2b9bccb4b63b2 100644 (file)
@@ -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);
 
index 9d93c9ab73cb5cd9dff5d0ca6d4accccb82558ec..d54ea3f862b38085dcea5575eaab3bf156d1f905 100644 (file)
@@ -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, \
index 3978e19c8c32e964bd646b8760f5623370eb8019..eb2a589e00bc51ac677b20d059bc2386778f9126 100644 (file)
@@ -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"
index 451595841899cd83dbca2be2ecacc3bb8a388414..67a2a2f4f6a4f0eb0558a0f664cbaa5e7ddc460f 100644 (file)
@@ -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"
index ab130947e1bdc4724d750ba9ef13d513f81c2612..2e99aa06909b8ffced9059ff890e46592e87e6de 100644 (file)
@@ -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]);
index ffa0012e6a2b95d5424d1d53e6b382500c5c2ac1..ceb9f932e2315663588128ead923f785302835bb 100644 (file)
@@ -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;
 
index 93c560458067799a6f490e9c171f7af5966e62c6..7b50c775d8d025d610f56c7c067ccb903a79351a 100644 (file)
@@ -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_
 
index 4c33330efd6beed627e145ba64c1ba83df8c2c29..c15481e9f109c0513f064d2e27c8be88c36f9932 100644 (file)
@@ -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.
  *
index 94bd07d44bf94d88db89c09add5c5f8edb2f2a85..69b3b21b2e3a294db2789c09db31d153cd9ffc86 100644 (file)
@@ -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);
index 717185fab330a6bdf78225ef70c65f8ac21b11d0..945b632ce0b4cd35296823772454fd48dcd7da8f 100644 (file)
@@ -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);
index 701e0d12da22b0b347c1006e349f66115f8aa345..4cb2d68b8ca6020f7e9a36a3fd45feaf0aefcb4c 100644 (file)
@@ -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);
index df4ab6ede7335701391741420cd1fddc041dcb7b..1753686a27c9f486e16c5daef8b0cb13944dbc8f 100644 (file)
@@ -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)) {