-// 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
#include <vector>
#include <string>
+#include <mutex>
#include <map>
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
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;
private:
~PlayGround();
private:
+ mutable std::mutex _locker;
std::vector< Resource > _data;
};