All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SegmenterIdsManager.cpp
Go to the documentation of this file.
1 #include "SegmenterIdsManager.h"
2 
3 namespace te
4 {
5  namespace rp
6  {
7 
9  {
11  }
12 
13 
15  {
16  }
17 
19  {
21 
22  m_mutex.lock();
23 
24  if( m_freeIDs.empty() )
25  {
26  if( m_segmentsIdsCounter < std::numeric_limits<
28  {
30  newId = m_segmentsIdsCounter;
31  }
32  }
33  else
34  {
35  newId = m_freeIDs.front();
36  m_freeIDs.pop_front();
37  }
38 
39  m_mutex.unlock();
40 
41  return newId;
42  }
43 
45  const unsigned int& idsNumber,
46  std::vector< SegmenterSegmentsBlock::SegmentIdDataType >& ids )
47  {
48  ids.resize( idsNumber );
49 
50  m_mutex.lock();
51 
52  for( unsigned int genIds = 0 ; genIds < idsNumber ; ++genIds )
53  {
54  if( m_freeIDs.empty() )
55  {
56  if( m_segmentsIdsCounter == std::numeric_limits<
58  {
59  m_mutex.unlock();
60  return false;
61  }
62  else
63  {
65  ids[ genIds ] = m_segmentsIdsCounter;
66  }
67  }
68  else
69  {
70  ids[ genIds ] = m_freeIDs.front();
71  m_freeIDs.pop_front();
72  }
73  }
74 
75  m_mutex.unlock();
76 
77  return true;
78  }
79 
81  {
82  m_mutex.lock();
83 
84  m_freeIDs.push_back( id );
85 
86  m_mutex.unlock();
87  }
88 
90  const std::vector< SegmenterSegmentsBlock::SegmentIdDataType >& ids )
91  {
92  m_mutex.lock();
93 
94  const unsigned int idsSize = (unsigned int)ids.size();
95 
96  for( unsigned int idsIdx = 0 ; idsIdx < idsSize ; ++idsIdx )
97  {
98  m_freeIDs.push_back( ids[ idsIdx ] );
99  }
100 
101  m_mutex.unlock();
102  }
103 
105  const std::list< SegmenterSegmentsBlock::SegmentIdDataType >& ids )
106  {
107  m_mutex.lock();
108 
109  std::list< SegmenterSegmentsBlock::SegmentIdDataType >::const_iterator
110  it = ids.begin();
111  std::list< SegmenterSegmentsBlock::SegmentIdDataType >::const_iterator
112  itEnd = ids.end();
113 
114  while( it != itEnd )
115  {
116  m_freeIDs.push_back( *it );
117  ++it;
118  }
119 
120  m_mutex.unlock();
121  }
122 
123  } // namespace rp
124 } // namespace te
void addFreeID(const SegmenterSegmentsBlock::SegmentIdDataType &id)
Stores a free unique ID for later use.
Segments IDs manager.
volatile SegmenterSegmentsBlock::SegmentIdDataType m_segmentsIdsCounter
std::list< SegmenterSegmentsBlock::SegmentIdDataType > m_freeIDs
void addFreeIDs(const std::vector< SegmenterSegmentsBlock::SegmentIdDataType > &ids)
Stores free unique IDs for later use.
SegmenterSegmentsBlock::SegmentIdDataType getNewID()
Returns a new segment unique ID.
bool getNewIDs(const unsigned int &idsNumber, std::vector< SegmenterSegmentsBlock::SegmentIdDataType > &ids)
Returns new segment unique IDs.