You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "adamdebreceni (via GitHub)" <gi...@apache.org> on 2023/05/18 10:22:05 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request, #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

adamdebreceni opened a new pull request, #1576:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576

   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #1576:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576#discussion_r1221378728


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -91,27 +90,26 @@ static sem_t *process_running;
 
 #ifdef WIN32
 BOOL WINAPI consoleSignalHandler(DWORD signal) {
-  if (!process_running) { exit(0); return TRUE; }
+  if (!process_running.test()) { exit(0); return TRUE; }
   if (signal == CTRL_C_EVENT || signal == CTRL_BREAK_EVENT) {
-    int ret = ETIMEDOUT;
-    while (ret == ETIMEDOUT) {
-      if (flow_controller_running) { sem_post(flow_controller_running); }
-      const struct timespec timeout_100ms { .tv_sec = 0, .tv_nsec = 100000000};
-      ret = sem_timedwait(process_running, &timeout_100ms);
-    }
+    flow_controller_running.clear();
+    flow_controller_running.notify_all();
+    process_running.wait(false);

Review Comment:
   should this be `wait(true)`?  from the docs, it looks to me that `wait(x)` waits for the flag to be _not_ x, and we want to wait for `process_running` to become `false` (ie, not `true`)



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

Posted by "adamdebreceni (via GitHub)" <gi...@apache.org>.
adamdebreceni commented on code in PR #1576:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576#discussion_r1198785129


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -91,27 +90,26 @@ static sem_t *process_running;
 
 #ifdef WIN32
 BOOL WINAPI consoleSignalHandler(DWORD signal) {
-  if (!process_running) { exit(0); return TRUE; }
+  if (!process_running.test()) { exit(0); return TRUE; }
   if (signal == CTRL_C_EVENT || signal == CTRL_BREAK_EVENT) {
-    int ret = ETIMEDOUT;
-    while (ret == ETIMEDOUT) {
-      if (flow_controller_running) { sem_post(flow_controller_running); }
-      const struct timespec timeout_100ms { .tv_sec = 0, .tv_nsec = 100000000};
-      ret = sem_timedwait(process_running, &timeout_100ms);
-    }
+    flow_controller_running.clear();
+    flow_controller_running.notify_all();
+    process_running.wait(false);
     return TRUE;
   }
   return FALSE;
 }
 
 void SignalExitProcess() {
-  sem_post(flow_controller_running);
+  flow_controller_running.clear();
+  flow_controller_running.notify_all();

Review Comment:
   according to the standard calling a non-static member function of `std::atomic_flag` is a "plain lock-free atomic operation" which is allowed in signal handlers



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] szaszm closed pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm closed pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

Posted by "adamdebreceni (via GitHub)" <gi...@apache.org>.
adamdebreceni commented on code in PR #1576:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576#discussion_r1221672759


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -91,27 +90,26 @@ static sem_t *process_running;
 
 #ifdef WIN32
 BOOL WINAPI consoleSignalHandler(DWORD signal) {
-  if (!process_running) { exit(0); return TRUE; }
+  if (!process_running.test()) { exit(0); return TRUE; }
   if (signal == CTRL_C_EVENT || signal == CTRL_BREAK_EVENT) {
-    int ret = ETIMEDOUT;
-    while (ret == ETIMEDOUT) {
-      if (flow_controller_running) { sem_post(flow_controller_running); }
-      const struct timespec timeout_100ms { .tv_sec = 0, .tv_nsec = 100000000};
-      ret = sem_timedwait(process_running, &timeout_100ms);
-    }
+    flow_controller_running.clear();
+    flow_controller_running.notify_all();
+    process_running.wait(false);

Review Comment:
   good catch, indeed that seems to be the case



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] szaszm commented on a diff in pull request #1576: MINIFICPP-2121 - Use std::atomic_flag instead of semaphore

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #1576:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1576#discussion_r1198737019


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -91,27 +90,26 @@ static sem_t *process_running;
 
 #ifdef WIN32
 BOOL WINAPI consoleSignalHandler(DWORD signal) {
-  if (!process_running) { exit(0); return TRUE; }
+  if (!process_running.test()) { exit(0); return TRUE; }
   if (signal == CTRL_C_EVENT || signal == CTRL_BREAK_EVENT) {
-    int ret = ETIMEDOUT;
-    while (ret == ETIMEDOUT) {
-      if (flow_controller_running) { sem_post(flow_controller_running); }
-      const struct timespec timeout_100ms { .tv_sec = 0, .tv_nsec = 100000000};
-      ret = sem_timedwait(process_running, &timeout_100ms);
-    }
+    flow_controller_running.clear();
+    flow_controller_running.notify_all();
+    process_running.wait(false);
     return TRUE;
   }
   return FALSE;
 }
 
 void SignalExitProcess() {
-  sem_post(flow_controller_running);
+  flow_controller_running.clear();
+  flow_controller_running.notify_all();

Review Comment:
   Is this approach signal safe?



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org