]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/SalomeHPContainerTools.hxx
Salome HOME
4b080d57e371b7f0edeade2b3ca81a8a2828c3fe
[modules/yacs.git] / src / runtime / SalomeHPContainerTools.hxx
1 // Copyright (C) 2006-2016  CEA/DEN, EDF R&D
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 #ifndef __SALOMEHPCONTAINERTOOLS_HXX__
21 #define __SALOMEHPCONTAINERTOOLS_HXX__
22
23 #include "YACSRuntimeSALOMEExport.hxx"
24 #include "SalomeContainerHelper.hxx"
25
26 #include "RefCounter.hxx"
27
28 #include "Mutex.hxx"
29 #include "AutoRefCnt.hxx"
30
31 #include <map>
32 #include <vector>
33
34 namespace YACS
35 {
36   namespace ENGINE
37   {
38     class Task;
39     class SalomeComponent;
40     class SalomeHPContainer;
41     class SalomeContainerMonoHelper;
42     class SalomeHPContainerVectOfHelper : public RefCounter
43     {
44     public:
45       std::size_t size() const { return _launchModeType.size(); }
46       void resize(std::size_t sz);
47       std::size_t getNumberOfFreePlace() const;
48       std::size_t getNumberOfFreePlaceAmong(const std::vector<std::size_t>& idsOfKernelContainers) const;
49       void allocateFor(const std::vector<const Task *>& nodes);
50       void allocateForAmong(const std::vector<std::size_t>& idsOfKernelContainers, const std::vector<const Task *>& nodes);
51       void release(const Task *node);
52       std::size_t locateTask(const Task *node) const;
53       const SalomeContainerMonoHelper *at(std::size_t pos) const { checkPosInVec(pos); return _launchModeType[pos]; }
54       SalomeContainerMonoHelper *at(std::size_t pos) { checkPosInVec(pos); return _launchModeType[pos]; }
55       const SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(const Task *node) const;
56       const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const;
57       SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(const Task *node);
58       SalomeContainerMonoHelper *getHelperOfTask(const Task *node);
59       void shutdown();
60       //! For thread safety for concurrent load operation on same Container.
61       void lock();
62       //! For thread safety for concurrent load operation on same Container.
63       void unLock();
64     private:
65       ~SalomeHPContainerVectOfHelper() { }
66       void checkNoCurrentWork() const;
67       void checkPosInVec(std::size_t pos) const;
68     private:
69       YACS::BASES::Mutex _mutex;
70       std::vector<bool> _whichOccupied;
71       std::vector< BASES::AutoRefCnt<YACS::ENGINE::SalomeContainerMonoHelper> > _launchModeType;
72       std::map<const Task *,std::size_t > _currentlyWorking;
73     };
74   }
75 }
76
77 #endif