]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime_swig/ThreadLauncher.cxx
Salome HOME
5e3de2bfe2fd6a7a00b09eea462de4dea1a2413d
[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         std::string cmd = "COPY /b " + _lock_file + " +,,";
46 #else 
47     sleep(_nb_seconds);
48     std::string cmd = "touch " + _lock_file;
49 #endif
50     system(cmd.c_str());
51     schemaSaveStateUnsafe(_proc,_dump_file);
52 #ifdef WIN32
53     cmd = "DEL /Q /F " + _lock_file;
54 #else
55     cmd = "rm -f " + _lock_file;
56 #endif
57     system(cmd.c_str());
58     state = _proc->getEffectiveState();
59   }
60 }
61
62 void ThreadDumpState::start()
63 {
64   _my_thread.reset( new std::thread([this]{
65     this->run();
66   }) );
67 }
68
69 void ThreadDumpState::join()
70 {
71   if(_my_thread)
72   {
73     AutoGIL agil;
74     AutoPyYielder yld;
75     _my_thread->join();
76     _my_thread.reset( nullptr );
77   }
78 }