]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime_swig/ThreadLauncher.cxx
Salome HOME
ff5b83c2ecb375fdb25d273dc2ef6a605eb5df63
[modules/yacs.git] / src / runtime_swig / ThreadLauncher.cxx
1 // Copyright (C) 2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ThreadLauncher.hxx"
21 #include "VisitorSalomeSaveState.hxx"
22
23 #include "PythonCppUtils.hxx"
24
25 #include "Basics_Utils.hxx"
26
27 #include "Python.h"
28
29 using namespace YACS::ENGINE;
30
31 ThreadDumpState::~ThreadDumpState()
32 {
33   join();
34 }
35
36 void ThreadDumpState::run()
37 {
38   AutoGIL agil;
39   AutoPyYielder yld;
40   YACS::StatesForNode state = _proc->getEffectiveState();
41   while((state != YACS::DONE) && (state != YACS::LOADFAILED) && (state != YACS::EXECFAILED) && (state != YACS::INTERNALERR) && (state != YACS::DISABLED) && (state != YACS::FAILED) && (state != YACS::ERROR))
42   {
43 #ifdef WIN32
44     Sleep(_nb_seconds);
45 #else 
46     sleep(_nb_seconds);
47 #endif
48     std::string cmd = "touch " + _lock_file;
49     system(cmd.c_str());
50     schemaSaveStateUnsafe(_proc,_dump_file);
51     cmd = "rm -f " + _lock_file;
52     system(cmd.c_str());
53     state = _proc->getEffectiveState();
54   }
55 }
56
57 void ThreadDumpState::start()
58 {
59   _my_thread.reset( new std::thread([this]{
60     this->run();
61   }) );
62 }
63
64 void ThreadDumpState::join()
65 {
66   if(_my_thread)
67   {
68     AutoGIL agil;
69     AutoPyYielder yld;
70     _my_thread->join();
71     _my_thread.reset( nullptr );
72   }
73 }