]> Kevux Git Server - fll/commitdiff
Bugfix: rules not properly handling status.
authorKevin Day <thekevinday@gmail.com>
Sun, 11 Apr 2021 21:53:54 +0000 (16:53 -0500)
committerKevin Day <thekevinday@gmail.com>
Sun, 11 Apr 2021 21:53:54 +0000 (16:53 -0500)
The status F_known_not was incorrectly being treated as busy.
Make sure to guarantee lock and then unlock of the process_other lock (read lock) to prevent execution of dependent rule while analyzing state of dependent rule.

Read the rule's status after executing from the rule in the rules array and not on the process.
The rules on the rules array is updated after execution but the process is not guaranteed this.
The status of process is generally reserved for the process to manage the status and not to represent the rule status.

Expanded the example serial execution test entries and rules.
Add a new alternative serial so that one uses normal execution and other uses dependent execution (execution is executed by something depending on it rather than being directly started via the entry).

15 files changed:
level_3/controller/c/private-rule.c
level_3/controller/data/settings/example/entries/serial-alternate.entry [new file with mode: 0644]
level_3/controller/data/settings/example/entries/serial.entry
level_3/controller/data/settings/example/rules/asynchronous/sleep_1.rule
level_3/controller/data/settings/example/rules/asynchronous/sleep_10.rule
level_3/controller/data/settings/example/rules/asynchronous/sleep_2.rule
level_3/controller/data/settings/example/rules/asynchronous/sleep_3.rule
level_3/controller/data/settings/example/rules/asynchronous/sleep_5.rule
level_3/controller/data/settings/example/rules/asynchronous/sleep_8.rule
level_3/controller/data/settings/example/rules/serial/s_1.rule
level_3/controller/data/settings/example/rules/serial/s_2.rule
level_3/controller/data/settings/example/rules/serial/s_3.rule
level_3/controller/data/settings/example/rules/serial/s_4.rule
level_3/controller/data/settings/example/rules/serial/s_5.rule
level_3/controller/data/settings/example/rules/serial/s_6.rule

index 33304e2..e901eb9 100644 (file)
@@ -1811,64 +1811,70 @@ extern "C" {
 
             busy = F_false;
 
-            status = f_thread_lock_read_try(&process_other->lock);
+            f_thread_lock_read(&process_other->lock);
 
-            if (status == F_busy) {
+            if (process_other->state == controller_process_state_active || process_other->state == controller_process_state_busy) {
               busy = F_true;
             }
-            else {
-              if (process_other->status == F_known_not || process_other->state == controller_process_state_active || process_other->state == controller_process_state_busy) {
-                busy = F_true;
-              }
 
+            if (busy) {
               f_thread_unlock(&process_other->lock);
-            }
 
-            if (busy) {
               controller_process_wait(main, process_other);
             }
             else {
-              rule_options = 0;
+              f_thread_lock_read(&main.thread->lock.rule);
 
-              if (main.data->parameters[controller_parameter_test].result == f_console_result_found) {
-                rule_options |= controller_rule_option_simulate;
-              }
+              if (main.setting->rules.array[id_rule].status == F_known_not) {
+                f_thread_unlock(&main.thread->lock.rule);
+                f_thread_unlock(&process_other->lock);
 
-              // synchronously execute dependency.
-              status = controller_rule_process_begin(controller_process_option_execute, alias_other, controller_rule_action_type_start, controller_process_option_execute, process->stack, main, process_other->cache);
+                rule_options = 0;
 
-              if (status == F_child || status == F_signal) {
-                f_thread_unlock(&process_other->active);
+                if (main.data->parameters[controller_parameter_test].result == f_console_result_found) {
+                  rule_options |= controller_rule_option_simulate;
+                }
 
-                break;
-              }
+                // synchronously execute dependency.
+                status = controller_rule_process_begin(controller_process_option_execute, alias_other, controller_rule_action_type_start, controller_process_option_execute, process->stack, main, process_other->cache);
 
-              if (F_status_is_error(status)) {
-                if (i == 0 || i == 1 || F_status_set_fine(status) == F_memory_not) {
-                  f_thread_mutex_lock(&main.thread->lock.print);
+                if (status == F_child || status == F_signal) {
+                  f_thread_unlock(&process_other->active);
 
-                  controller_rule_item_error_print_need_want_wish(main.data->error, strings[i], alias_other_buffer, "failed during execution");
-                  controller_rule_error_print_cache(main.data->error, process->cache.action, F_true);
+                  break;
+                }
 
-                  controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print);
+                if (F_status_is_error(status)) {
+                  if (i == 0 || i == 1 || F_status_set_fine(status) == F_memory_not) {
+                    f_thread_mutex_lock(&main.thread->lock.print);
 
-                  if (!(process_other->options & controller_rule_option_simulate) || F_status_set_fine(status) == F_memory_not) {
-                    f_thread_unlock(&process_other->active);
+                    controller_rule_item_error_print_need_want_wish(main.data->error, strings[i], alias_other_buffer, "failed during execution");
+                    controller_rule_error_print_cache(main.data->error, process->cache.action, F_true);
+
+                    controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print);
+
+                    if (!(process_other->options & controller_rule_option_simulate) || F_status_set_fine(status) == F_memory_not) {
+                      f_thread_unlock(&process_other->active);
 
-                    break;
+                      break;
+                    }
                   }
-                }
-                else {
-                  if (main.data->warning.verbosity == f_console_verbosity_debug) {
-                    f_thread_mutex_lock(&main.thread->lock.print);
+                  else {
+                    if (main.data->warning.verbosity == f_console_verbosity_debug) {
+                      f_thread_mutex_lock(&main.thread->lock.print);
 
-                    controller_rule_item_error_print_need_want_wish(main.data->warning, strings[i], alias_other_buffer, "failed during execution");
-                    controller_rule_error_print_cache(main.data->warning, process->cache.action, F_true);
+                      controller_rule_item_error_print_need_want_wish(main.data->warning, strings[i], alias_other_buffer, "failed during execution");
+                      controller_rule_error_print_cache(main.data->warning, process->cache.action, F_true);
 
-                    controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print);
+                      controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print);
+                    }
                   }
                 }
               }
+              else {
+                f_thread_unlock(&main.thread->lock.rule);
+                f_thread_unlock(&process_other->lock);
+              }
             }
 
             if (!main.thread->enabled) {
@@ -1942,7 +1948,7 @@ extern "C" {
     }
 
     if ((process->options & controller_rule_option_wait) && F_status_is_error_not(status)) {
-      controller_rule_wait_all(main, process); // @fixme review this, it needs to check anything depending on itself!
+      controller_rule_wait_all(main, process); // @fixme review this, it needs to check anything depending on this!
 
       if (!main.thread->enabled) {
         return F_signal;
diff --git a/level_3/controller/data/settings/example/entries/serial-alternate.entry b/level_3/controller/data/settings/example/entries/serial-alternate.entry
new file mode 100644 (file)
index 0000000..5b26299
--- /dev/null
@@ -0,0 +1,11 @@
+# fss-0005
+
+main:
+  rule serial s_1
+  rule serial s_2
+  rule serial s_3
+  rule serial s_4
+  rule serial s_5
+  rule serial s_6
+
+  ready
index e055c16..de7c696 100644 (file)
@@ -7,7 +7,7 @@ setting:
   need asynchronous sleep_10
 
 script:
-  start echo "Sleeping 1: $(date -u)"
+  start echo "Sleeping 1: $(date -u), depends: 10"
 
 script:
   start sleep 1
index 63d644c..db6a70c 100644 (file)
@@ -6,7 +6,7 @@ setting:
   limit nice 1 2
 
 script:
-  start echo "Sleeping 10: $(date -u)"
+  start echo "Sleeping 10: $(date -u), depends: none"
 
 script:
   start sleep 10
index 77cbab5..40f3f4c 100644 (file)
@@ -7,7 +7,7 @@ setting:
   need asynchronous sleep_10
 
 script:
-  start echo "Sleeping 2: $(date -u)"
+  start echo "Sleeping 2: $(date -u), depends: 10"
 
 script:
   start sleep 2
index de91412..de403b6 100644 (file)
@@ -7,7 +7,7 @@ setting:
   need asynchronous sleep_8
 
 script:
-  start echo "Sleeping 3: $(date -u)"
+  start echo "Sleeping 3: $(date -u), depends: 8"
 
 script:
   start sleep 3
index ecac2f5..f40234b 100644 (file)
@@ -6,7 +6,7 @@ setting:
   limit nice 1 2
 
 script:
-  start echo "Sleeping 5: $(date -u)"
+  start echo "Sleeping 5: $(date -u), depends: none"
 
 script:
   start sleep 5
index 34d919b..a05a249 100644 (file)
@@ -6,7 +6,7 @@ setting:
   limit nice 1 2
 
 script:
-  start echo "Sleeping 8: $(date -u)"
+  start echo "Sleeping 8: $(date -u), depends: none"
 
 script:
   start sleep 8
index f434357..af975d1 100644 (file)
@@ -5,6 +5,7 @@ setting:
 
 script:
   start {
-    echo "Serial 1: $(date -u)"
+    echo "Serial 1: sleeping $(date -u)"
     sleep 1
+    echo "Serial 1: slept    $(date -u)"
   }
index 1846b09..be526d7 100644 (file)
@@ -6,6 +6,7 @@ setting:
 
 script:
   start {
-    echo "Serial 2: $(date -u)"
+    echo "Serial 2: sleeping $(date -u)"
     sleep 1
+    echo "Serial 2: slept    $(date -u)"
   }
index 9b0ef02..124de75 100644 (file)
@@ -6,6 +6,7 @@ setting:
 
 script:
   start {
-    echo "Serial 3: $(date -u)"
+    echo "Serial 3: sleeping $(date -u)"
     sleep 1
+    echo "Serial 3: slept    $(date -u)"
   }
index 46217ab..beb52f7 100644 (file)
@@ -6,6 +6,7 @@ setting:
 
 script:
   start {
-    echo "Serial 4: $(date -u)"
+    echo "Serial 4: sleeping $(date -u)"
     sleep 1
+    echo "Serial 4: slept    $(date -u)"
   }
index f180252..eb6aab8 100644 (file)
@@ -6,6 +6,7 @@ setting:
 
 script:
   start {
-    echo "Serial 5: $(date -u)"
+    echo "Serial 5: sleeping $(date -u)"
     sleep 1
+    echo "Serial 5: slept    $(date -u)"
   }
index ec3b020..af3bc82 100644 (file)
@@ -6,6 +6,7 @@ setting:
 
 script:
   start {
-    echo "Serial 6: $(date -u)"
+    echo "Serial 6: sleeping $(date -u)"
     sleep 1
+    echo "Serial 6: slept    $(date -u)"
   }