szaszm commented on code in PR #2292:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2292#discussion_r4480471783


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -79,6 +81,41 @@ namespace utils = minifi::utils;
 static std::atomic_flag flow_controller_running;
 static std::atomic_flag process_running;
 
+enum class LifecycleState : int32_t {
+  RUNNING,
+  RESTART_REQUESTED,
+  SHUTDOWN_REQUESTED
+};
+
+struct LifecycleRequest {
+  LifecycleState state = LifecycleState::RUNNING;
+  int32_t exit_code = 0;
+};
+
+static_assert(std::atomic<LifecycleRequest>::is_always_lock_free);

Review Comment:
   I'd remove this. Lockfree 64bit stores are nice to have, but falling back to 
locks is fine for our needs too.



##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -79,6 +81,41 @@ namespace utils = minifi::utils;
 static std::atomic_flag flow_controller_running;
 static std::atomic_flag process_running;
 
+enum class LifecycleState : int32_t {
+  RUNNING,
+  RESTART_REQUESTED,
+  SHUTDOWN_REQUESTED
+};
+
+struct LifecycleRequest {
+  LifecycleState state = LifecycleState::RUNNING;
+  int32_t exit_code = 0;
+};
+
+static_assert(std::atomic<LifecycleRequest>::is_always_lock_free);
+static std::atomic<LifecycleRequest> lifecycle_request;
+
+bool requestLifecycleChange(minifi::ShutdownType shutdown_type, int32_t 
exit_code) {
+  auto current_request = lifecycle_request.load();
+  while (true) {

Review Comment:
   The load should be in the loop, otherwise if there is a race condition, the 
stale `current_request` will never match the new value of lifecycle_request, 
and I think we'd get stuck in an infinite loop.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to