From: Kevin Day Date: Sat, 13 Jul 2024 04:28:38 +0000 (-0500) Subject: Update: Use copy of flag to avoid possible race conditions with controller_thread_is_... X-Git-Tag: 0.6.11~19 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f9c8d8e731928a9705d0208046b2a7faf92ccf32;p=fll Update: Use copy of flag to avoid possible race conditions with controller_thread_is_enabled(). The thread.enabled is checked multiple times in controller_thread_is_enabled() but this value may have changed. Make a constant copy and reference that copy so that any changes after the first read will not affect the function results. --- diff --git a/level_3/controller/c/thread/private-thread.c b/level_3/controller/c/thread/private-thread.c index 3aa9c74..e06ee57 100644 --- a/level_3/controller/c/thread/private-thread.c +++ b/level_3/controller/c/thread/private-thread.c @@ -172,11 +172,9 @@ extern "C" { #ifndef _di_controller_thread_is_enabled_ f_status_t controller_thread_is_enabled(const bool is_normal, controller_thread_t * const thread) { - if (is_normal) { - return thread->enabled == controller_thread_enabled_e; - } + const bool enabled = thread->enabled; - return thread->enabled; + return is_normal ? enabled == controller_thread_enabled_e : enabled; } #endif // _di_controller_thread_is_enabled_