1 // Copyright (C) 2020-2021 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
19 #ifndef WORKLOADMANAGER_H
20 #define WORKLOADMANAGER_H
21 #include "YACSlibWorkloadmanagerExport.hxx"
25 #include <condition_variable> // notifications
30 #include "WorkloadAlgorithm.hxx"
32 namespace WorkloadManager
34 class YACSLIBWLM_EXPORT WorkloadManager
37 WorkloadManager(WorkloadAlgorithm& algo);
38 WorkloadManager(const WorkloadManager&) = delete;
39 WorkloadManager()=delete;
41 void addTask(Task* t);
42 void addResource(const Resource& r);
43 void freezeResources(); //! no more resources can be added
44 void start(); //! start execution
45 void stop(); //! stop execution
48 typedef unsigned long TaskId;
52 WorkloadAlgorithm::LaunchInfo info;
54 std::map<TaskId, std::future<void> > _runningTasks;
55 std::queue<RunningInfo> _finishedTasks;
57 std::mutex _data_mutex;
58 std::condition_variable _startCondition; // start tasks thread notification
59 std::condition_variable _endCondition; // end tasks thread notification
61 std::vector< std::future<void> > _otherThreads;
62 WorkloadAlgorithm& _algo;
66 void runOneTask(const RunningInfo& taskInfo);
67 // choose a task and block a resource
68 bool chooseTaskToRun(RunningInfo& taskInfo);
71 #endif // WORKLOADMANAGER_H