ATLAS Offline Software
LWPoolAreaBookKeeper.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #undef LW_FIELDS
6 #define LW_FIELDS (reinterpret_cast<BitField*>(reinterpret_cast<char*>(this)+sizeof(LWPoolAreaBookKeeper)))
7 
8 inline bool LWPoolAreaBookKeeper::isCompletelyFull() const
9 {
10  return m_nUnusedEntries==m_nEntries;
11 }
12 
13 inline bool LWPoolAreaBookKeeper::isCompletelyEmpty() const
14 {
15  return m_nUnusedEntries==0;
16 }
17 
18 inline unsigned LWPoolAreaBookKeeper::numberOfAvailableEntries() const
19 {
20  return m_nUnusedEntries;
21 }
22 
23 inline unsigned LWPoolAreaBookKeeper::numberOfEntriesHandedOut() const
24 {
25  return m_nEntries-m_nUnusedEntries;
26 }
27 
28 //____________________________________________________________________
29 inline void LWPoolAreaBookKeeper::returnEntry(unsigned iEntry)
30 {
31  assert(!isCompletelyFull());
32  const unsigned iField(iEntry/LW_ENTRIESPERGROUP);
33  const unsigned iBit(iEntry%LW_ENTRIESPERGROUP);
34  BitField & b = LW_FIELDS[iField];
35  //Toggle the bit to set it:
36  assert( ! (b & 1 << iBit) );
37  b ^= 1 << iBit;
38  assert(b & 1 << iBit);
39  assert(b);
40  m_nonEmptyField = iField;
41  ++m_nUnusedEntries;
42 }
43 
44 //____________________________________________________________________
45 inline unsigned LWPoolAreaBookKeeper::acquireEntry()
46 {
47  assert((m_nonEmptyField==UINT_MAX)==(!m_nUnusedEntries));
48  if (!m_nUnusedEntries)
49  return UINT_MAX;
50  assert(!isCompletelyEmpty());
51  BitField & b = LW_FIELDS[m_nonEmptyField];
52  assert(b);
53  const unsigned firstSetBit = ffs(b)-1;//ffs(..) starts at 1 if rightmost bit is set,
54  //etc., up to 32 if only the leftmost
55  //bit is set.
56  assert(firstSetBit<LW_ENTRIESPERGROUP);
57 
58 
59  //Remember:
60  //Set bit x in number: number |= 1 << x;
61  //Clear bit x in number: number &= ~(1 << x);
62  //Toggle bit x in number: number ^= 1 << x;
63 
64  //Toggle the bit to clear it:
65  assert(b & 1 << firstSetBit);
66  b ^= 1 << firstSetBit;
67  assert( ! (b & 1 << firstSetBit) );
68 
69  const unsigned iEntry(LW_ENTRIESPERGROUP*m_nonEmptyField+firstSetBit);
70  if (!b)
71  findNewNonEmptyField();
72  --m_nUnusedEntries;
73  assert((m_nonEmptyField==UINT_MAX)==(!m_nUnusedEntries));
74  return iEntry;
75 }
76 #undef LW_FIELDS