Salome HOME
[EDF28020] Fix nested foreach-switch.
[modules/yacs.git] / src / engine / PlayGround.hxx
index 07e9f081307b3de4dc6eebf60b595eaa2c2b0d63..0b1a9190c4e33c1db3c69db3ebd7183132dd39ad 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -27,6 +27,7 @@
 
 #include <vector>
 #include <string>
+#include <mutex>
 #include <map>
 
 namespace YACS
@@ -43,13 +44,18 @@ namespace YACS
       std::pair<std::string,int> toPair() const { return {_name,_nbCores}; }
       int nbCores() const { return _nbCores; }
       std::string name() const { return _name; }
+      std::size_t getNumberOfFreePlace(int nbCoresPerCont) const;
+      std::vector<std::size_t> allocateFor(std::size_t& nbOfPlacesToTake, int nbCoresPerCont) const;
+      void release(std::size_t workerId, int nbCoresPerCont) const;
+      std::size_t getNumberOfWorkers(int nbCoresPerCont) const;
+      void printSelf(std::ostream& oss) const;
     private:
       std::string _name;
       int _nbCores;
-      std::vector<bool> _occupied;
+      mutable std::vector<bool> _occupied;
     };
-    
-    
+
+
     class ResourceIterator : public std::iterator<
                         std::input_iterator_tag,     // iterator_category
                         Resource,                    // value_type
@@ -88,6 +94,12 @@ namespace YACS
       std::vector<std::size_t> getWorkerIdsFullyFetchedBy(int nbCoresPerComp, const std::vector<bool>& coreFlags) const;
       static std::vector<int> BuildVectOfIdsFromVecBool(const std::vector<bool>& v);
       static std::vector<int> GetIdsMatching(const std::vector<bool>& bigArr, const std::vector<bool>& pat);
+    public:// critical section part
+      std::size_t getNumberOfFreePlace(int nbCoresPerCont) const;
+      std::vector<std::size_t> allocateFor(std::size_t nbOfPlacesToTake, int nbCoresPerCont) const;
+      void release(std::size_t workerId, int nbCoresPerCont) const;
+      std::mutex& getLocker() const { return _locker; }
+      void printMe() const;
     private:
       std::vector< std::pair <const ComplexWeight *, int> > bigToTiny(const std::vector< std::pair <const ComplexWeight *, int> > &weights, std::map<int,int> &saveOrder) const;
          std::vector< std::vector<int> > backToOriginalOrder(const std::vector< std::vector<int> > &disorderVec, const std::map<int,int> &saveOrder) const;
@@ -99,6 +111,7 @@ namespace YACS
     private:
       ~PlayGround();
     private:
+      mutable std::mutex _locker;
       std::vector< Resource > _data;
     };