Version: 9.16.0
YACS::ENGINE::Resource Class Reference

#include <PlayGround.hxx>

Collaboration diagram for YACS::ENGINE::Resource:

Public Member Functions

 Resource (const std::string &name, int nbCores)
 
 Resource (const std::pair< std::string, int > &p)
 
std::pair< std::string, int > toPair () const
 
int nbCores () const
 
std::string name () const
 
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 Attributes

std::string _name
 
int _nbCores
 
std::vector< bool > _occupied
 

Detailed Description

Definition at line 39 of file PlayGround.hxx.

Constructor & Destructor Documentation

◆ Resource() [1/2]

YACS::ENGINE::Resource::Resource ( const std::string &  name,
int  nbCores 
)
inline

Definition at line 42 of file PlayGround.hxx.

std::vector< bool > _occupied
Definition: PlayGround.hxx:55
std::string name() const
Definition: PlayGround.hxx:46

◆ Resource() [2/2]

YACS::ENGINE::Resource::Resource ( const std::pair< std::string, int > &  p)
inline

Definition at line 43 of file PlayGround.hxx.

43:_name(p.first),_nbCores(p.second),_occupied(_nbCores,false) { }
Proc * p
Definition: driver.cxx:216

Member Function Documentation

◆ allocateFor()

std::vector< std::size_t > Resource::allocateFor ( std::size_t &  nbOfPlacesToTake,
int  nbCoresPerCont 
) const

Definition at line 49 of file PlayGround.cxx.

50{
51 std::vector<std::size_t> ret;
52 std::size_t pos(0),curWorkerId(0);
53 while( ( pos < _occupied.size() ) && ( nbOfPlacesToTake > 0 ) )
54 {
55 bool isChunckFree(true);
56 int posInChunck(0);
57 for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
58 if(_occupied[pos])
59 isChunckFree = false;
60 if( isChunckFree && (posInChunck == nbCoresPerCont) )
61 {
62 for(int i = 0 ; i < nbCoresPerCont ; ++i)
63 _occupied[pos-nbCoresPerCont+i] = true;
64 ret.push_back(curWorkerId);
65 --nbOfPlacesToTake;
66 }
67 ++curWorkerId;
68 }
69 return ret;
70}

References _occupied, and yacsorb.CORBAEngineTest::i.

◆ getNumberOfFreePlace()

std::size_t Resource::getNumberOfFreePlace ( int  nbCoresPerCont) const

Definition at line 33 of file PlayGround.cxx.

34{
35 std::size_t ret(0),pos(0);
36 while( pos < _occupied.size() )
37 {
38 bool isChunckFree(true);
39 int posInChunck(0);
40 for( ; ( posInChunck < nbCoresPerCont ) && ( pos < _occupied.size() ) ; ++posInChunck, ++pos)
41 if(_occupied[pos])
42 isChunckFree = false;
43 if( isChunckFree && (posInChunck == nbCoresPerCont) )
44 ret++;
45 }
46 return ret;
47}

References _occupied.

◆ getNumberOfWorkers()

std::size_t Resource::getNumberOfWorkers ( int  nbCoresPerCont) const

Definition at line 85 of file PlayGround.cxx.

86{
87 return static_cast<std::size_t>(this->nbCores())/static_cast<std::size_t>(nbCoresPerCont);
88}

References nbCores().

Referenced by release().

◆ name()

std::string YACS::ENGINE::Resource::name ( ) const
inline

Definition at line 46 of file PlayGround.hxx.

46{ return _name; }

Referenced by printSelf().

◆ nbCores()

int YACS::ENGINE::Resource::nbCores ( ) const
inline

Definition at line 45 of file PlayGround.hxx.

45{ return _nbCores; }

Referenced by getNumberOfWorkers(), and printSelf().

◆ printSelf()

void Resource::printSelf ( std::ostream &  oss) const

Definition at line 90 of file PlayGround.cxx.

91{
92 oss << this->name() << " (" << this->nbCores() << ") : ";
93 for(auto it : this->_occupied)
94 {
95 if(it)
96 oss << "1";
97 else
98 oss << "0";
99 }
100}

References _occupied, name(), and nbCores().

◆ release()

void Resource::release ( std::size_t  workerId,
int  nbCoresPerCont 
) const

Definition at line 72 of file PlayGround.cxx.

73{
74 if(workerId >= this->getNumberOfWorkers(nbCoresPerCont))
75 throw Exception("Resource::release : invalid worker id !");
76 std::size_t pos(workerId*static_cast<std::size_t>(nbCoresPerCont));
77 for(int i = 0 ; i < nbCoresPerCont ; ++i)
78 {
79 if(!_occupied[pos + static_cast<std::size_t>(i)])
80 throw Exception("Resource::release : internal error ! A core is expected to be occupied !");
81 _occupied[pos + static_cast<std::size_t>(i)] = false;
82 }
83}
std::size_t getNumberOfWorkers(int nbCoresPerCont) const
Definition: PlayGround.cxx:85

References _occupied, getNumberOfWorkers(), and yacsorb.CORBAEngineTest::i.

◆ toPair()

std::pair< std::string, int > YACS::ENGINE::Resource::toPair ( ) const
inline

Definition at line 44 of file PlayGround.hxx.

44{ return {_name,_nbCores}; }

Member Data Documentation

◆ _name

std::string YACS::ENGINE::Resource::_name
private

Definition at line 53 of file PlayGround.hxx.

◆ _nbCores

int YACS::ENGINE::Resource::_nbCores
private

Definition at line 54 of file PlayGround.hxx.

◆ _occupied

std::vector<bool> YACS::ENGINE::Resource::_occupied
mutableprivate

Definition at line 55 of file PlayGround.hxx.

Referenced by allocateFor(), getNumberOfFreePlace(), printSelf(), and release().


The documentation for this class was generated from the following files: