소스 검색

Merge pull request #5448 from wangkx/h10883

HPCC-10313 Stop Ws_fs/WsWorkunits Schedule thread correctly

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 년 전
부모
커밋
3d36eb1b23

+ 2 - 3
esp/services/ws_fs/ws_fsService.cpp

@@ -48,7 +48,7 @@ int Schedule::run()
 {
     try
     {
-        while(true)
+        while(!stopping)
         {
             {
                 Owned<IDFUWorkUnitFactory> factory = getDFUWorkUnitFactory();
@@ -78,7 +78,7 @@ int Schedule::run()
                     itr->next();
                 }
             }
-            sleep(60);
+            semSchedule.wait(1000*60);
         }
     }
     catch(IException *e)
@@ -91,7 +91,6 @@ int Schedule::run()
     {
         ERRLOG("Unknown exception in WS_FS Schedule::run");
     }
-
     return 0;
 }
 

+ 13 - 0
esp/services/ws_fs/ws_fsService.hpp

@@ -25,8 +25,21 @@
 
 class Schedule : public Thread
 {
+    bool stopping;
+    Semaphore semSchedule;
     IEspContainer* m_container;
 public:
+    Schedule()
+    {
+        stopping = false;
+    };
+    ~Schedule()
+    {
+        stopping = true;
+        semSchedule.signal();
+        join();
+    }
+
     virtual int run();
     virtual void setContainer(IEspContainer * container)
     {

+ 2 - 2
esp/services/ws_workunits/ws_workunitsHelpers.cpp

@@ -2617,7 +2617,7 @@ int WUSchedule::run()
 {
     try
     {
-        while(true)
+        while(!stopping)
         {
             Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
             Owned<IConstWorkUnitIterator> itr = factory->getWorkUnitsByState(WUStateScheduled);
@@ -2652,7 +2652,7 @@ int WUSchedule::run()
                     }
                 }
             }
-            sleep(60);
+            semSchedule.wait(1000*60);
         }
     }
     catch(IException *e)

+ 13 - 0
esp/services/ws_workunits/ws_workunitsHelpers.hpp

@@ -317,9 +317,22 @@ void xsltTransform(const char* xml, const char* sheet, IProperties *params, Stri
 
 class WUSchedule : public Thread
 {
+    bool stopping;
+    Semaphore semSchedule;
     IEspContainer* m_container;
 
 public:
+    WUSchedule()
+    {
+        stopping = false;
+    }
+    ~WUSchedule()
+    {
+        stopping = true;
+        semSchedule.signal();
+        join();
+    }
+
     virtual int run();
     virtual void setContainer(IEspContainer * container)
     {