changeset 1101:e5686a703c63

ServerBarrier with external stop condition
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Aug 2014 10:21:43 +0200
parents f21f7783f934
children ce6386b37afd
files Core/Toolbox.cpp Core/Toolbox.h
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Thu Aug 07 10:11:43 2014 +0200
+++ b/Core/Toolbox.cpp	Thu Aug 07 10:21:43 2014 +0200
@@ -124,7 +124,7 @@
   }
 
 
-  void Toolbox::ServerBarrier()
+  static void ServerBarrierInternal(bool* stopFlag)
   {
 #if defined(_WIN32)
     SetConsoleCtrlHandler(ConsoleControlHandler, true);
@@ -134,10 +134,11 @@
     signal(SIGTERM, SignalHandler);
 #endif
   
+    // Active loop that awakens every 100ms
     finish = false;
-    while (!finish)
+    while (!(*stopFlag || finish))
     {
-      USleep(100000);
+      Toolbox::USleep(100 * 1000);
     }
 
 #if defined(_WIN32)
@@ -150,6 +151,17 @@
   }
 
 
+  void Toolbox::ServerBarrier(bool& stopFlag)
+  {
+    ServerBarrierInternal(&stopFlag);
+  }
+
+  void Toolbox::ServerBarrier()
+  {
+    bool stopFlag = false;
+    ServerBarrierInternal(&stopFlag);
+  }
+
 
   void Toolbox::ToUpperCase(std::string& s)
   {
--- a/Core/Toolbox.h	Thu Aug 07 10:11:43 2014 +0200
+++ b/Core/Toolbox.h	Thu Aug 07 10:21:43 2014 +0200
@@ -49,6 +49,8 @@
 
   namespace Toolbox
   {
+    void ServerBarrier(bool& stopFlag);
+
     void ServerBarrier();
 
     void ToUpperCase(std::string& s);  // Inplace version