1 // Copyright (C) 2006-2015 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")
49 /*! \brief Threaded Executor
55 class YACSLIBENGINE_EXPORT Executor
58 Scheduler *_mainSched;
60 int _nbOfConcurrentThreads;
61 YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
62 YACS::BASES::Condition _condForNewTasksToPerform;
63 YACS::BASES::Semaphore _semForMaxThreads;
64 YACS::BASES::Condition _condForStepByStep;
65 YACS::BASES::Condition _condForPilot;
66 YACS::BASES::Mutex _mutexForSchedulerUpdate;
67 YACS::BASES::Mutex _mutexForTrace;
70 bool _stopOnErrorRequested;
71 bool _dumpOnErrorRequested;
73 bool _isRunningunderExternalControl;
74 bool _isWaitingEventsFromRunningTasks;
75 int _numberOfRunningTasks;
76 std::set<Task *> _runningTasks;
77 int _numberOfEndedTasks;
79 YACS::ExecutorState _executorState;
80 YACS::ExecutionMode _execMode;
81 std::list<std::string> _listOfBreakPoints;
82 std::list<std::string> _listOfTasksToLoad;
83 std::vector<Task *> _tasks;
84 std::vector<Task *> _tasksSave;
85 std::list< YACS::BASES::Thread * > _groupOfAllThreadsCreated;
87 std::string _dumpErrorFile;
88 bool _keepGoingOnFail;
97 void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
98 void RunW(Scheduler *graph,int debug=0, bool fromScratch=true) { RunB(graph, debug, fromScratch); }
99 void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
100 void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
101 bool getKeepGoingProperty() const { return _keepGoingOnFail; }
102 YACS::ExecutionMode getCurrentExecMode();
103 YACS::ExecutorState getExecutorState();
104 void setExecMode(YACS::ExecutionMode mode);
105 void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
106 std::list<std::string> getTasksToLoad();
107 bool setStepsToExecute(std::list<std::string> listToExecute);
108 bool resumeCurrentBreakPoint();
109 bool isNotFinished();
110 void stopExecution();
111 bool saveState(const std::string& xmlFile);
113 int getNbOfThreads();
114 int getNumberOfRunningTasks() const { return _numberOfRunningTasks; }
115 void displayDot(Scheduler *graph);
116 void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
117 void unsetStopOnError();
119 static int _maxThreads;
120 static size_t _threadStackSize;
121 YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
123 bool checkBreakPoints();
125 void loadTask(Task *task, const Executor *execInst);
126 void loadTasks(const std::vector<Task *>& tasks, const Executor *execInst);
127 void loadParallelTasks(const std::vector<Task *>& tasks, const Executor *execInst);
128 void launchTasks(const std::vector<Task*>& tasks);
129 void launchTask(Task *task);
131 void sleepWhileNoEventsFromAnyRunningTask();
132 void notifyEndOfThread(YACS::BASES::Thread *thread);
133 void traceExec(Task *task, const std::string& message, const std::string& placement);
134 void _displayDot(Scheduler *graph);
135 virtual void sendEvent(const std::string& event);
136 static void FilterTasksConsideringContainers(std::vector<Task *>& tsks);
137 static std::string ComputePlacement(Task *zeTask);
139 static void *functionForTaskLoad(void *);
140 static void *functionForTaskExecution(void *);