1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __EXECUTOR_HXX__
21 #define __EXECUTOR_HXX__
23 #include "YACSlibEngineExport.hxx"
26 #include "Semaphore.hxx"
27 #include "Exception.hxx"
32 #pragma comment(lib,"winmm.lib")
50 /*! \brief Threaded Executor
56 class YACSLIBENGINE_EXPORT Executor
59 Scheduler *_mainSched;
61 int _nbOfConcurrentThreads;
62 YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
63 YACS::BASES::Condition _condForNewTasksToPerform;
64 YACS::BASES::Semaphore _semForMaxThreads;
65 YACS::BASES::Condition _condForStepByStep;
66 YACS::BASES::Condition _condForPilot;
67 YACS::BASES::Mutex _mutexForSchedulerUpdate;
68 YACS::BASES::Mutex _mutexForTrace;
71 bool _stopOnErrorRequested;
72 bool _dumpOnErrorRequested;
74 bool _isRunningunderExternalControl;
75 bool _isWaitingEventsFromRunningTasks;
76 int _numberOfRunningTasks;
77 std::set<Task *> _runningTasks;
78 int _numberOfEndedTasks;
80 YACS::ExecutorState _executorState;
81 YACS::ExecutionMode _execMode;
82 std::list<std::string> _listOfBreakPoints;
83 std::list<std::string> _listOfTasksToLoad;
84 std::vector<Task *> _tasks;
85 std::vector<Task *> _tasksSave;
86 std::list< YACS::BASES::Thread * > _groupOfAllThreadsCreated;
88 std::string _dumpErrorFile;
89 bool _keepGoingOnFail;
90 //! specifies if scope DynParaLoop is active or not. False by default.
91 bool _DPLScopeSensitive;
92 std::chrono::steady_clock::time_point _start;
96 void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
97 void RunW(Scheduler *graph,int debug=0, bool fromScratch=true)
99 //RunB(graph, debug, fromScratch);
100 newRun(graph, debug, fromScratch);
102 void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
103 void newRun(Scheduler *graph,int debug=0, bool fromScratch=true);
104 void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
105 bool getKeepGoingProperty() const { return _keepGoingOnFail; }
106 void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; }
107 bool getDPLScopeSensitive() const { return _DPLScopeSensitive; }
108 YACS::ExecutionMode getCurrentExecMode();
109 YACS::ExecutorState getExecutorState();
110 void setExecMode(YACS::ExecutionMode mode);
111 void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
112 std::list<std::string> getTasksToLoad();
113 bool setStepsToExecute(std::list<std::string> listToExecute);
114 bool resumeCurrentBreakPoint();
115 bool isNotFinished();
116 void stopExecution();
117 bool saveState(const std::string& xmlFile);
119 int getNbOfThreads();
120 int getNumberOfRunningTasks() const { return _numberOfRunningTasks; }
121 void displayDot(Scheduler *graph);
122 void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
123 void unsetStopOnError();
126 void resume(bool suspended);
127 static int _maxThreads;
128 static size_t _threadStackSize;
129 YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
130 ///// new executor !!!!!
131 void loadTask(Task *task);
132 YACS::Event runTask(Task *task);
133 void makeDatastreamConnections(Task *task);
134 void beginTask(Task *task);
135 void endTask(Task *task, YACS::Event ev);
138 bool checkBreakPoints();
140 void loadTask(Task *task, const Executor *execInst);
141 void loadParallelTasks(const std::vector<Task *>& tasks, const Executor *execInst);
142 void launchTasks(const std::vector<Task*>& tasks);
143 void launchTask(Task *task);
145 void sleepWhileNoEventsFromAnyRunningTask();
146 void notifyEndOfThread(YACS::BASES::Thread *thread);
147 void traceExec(Task *task, const std::string& message, const std::string& placement);
148 void _displayDot(Scheduler *graph);
149 virtual void sendEvent(const std::string& event);
150 static void FilterTasksConsideringContainers(std::vector<Task *>& tsks);
151 static std::string ComputePlacement(Task *zeTask);
153 static void *functionForTaskLoad(void *);
154 static void *functionForTaskExecution(void *);