2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
6 #define LW_FIELDS (reinterpret_cast<BitField*>(reinterpret_cast<char*>(this)+sizeof(LWPoolAreaBookKeeper)))
8 inline bool LWPoolAreaBookKeeper::isCompletelyFull() const
10 return m_nUnusedEntries==m_nEntries;
13 inline bool LWPoolAreaBookKeeper::isCompletelyEmpty() const
15 return m_nUnusedEntries==0;
18 inline unsigned LWPoolAreaBookKeeper::numberOfAvailableEntries() const
20 return m_nUnusedEntries;
23 inline unsigned LWPoolAreaBookKeeper::numberOfEntriesHandedOut() const
25 return m_nEntries-m_nUnusedEntries;
28 //____________________________________________________________________
29 inline void LWPoolAreaBookKeeper::returnEntry(unsigned iEntry)
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) );
38 assert(b & 1 << iBit);
40 m_nonEmptyField = iField;
44 //____________________________________________________________________
45 inline unsigned LWPoolAreaBookKeeper::acquireEntry()
47 assert((m_nonEmptyField==UINT_MAX)==(!m_nUnusedEntries));
48 if (!m_nUnusedEntries)
50 assert(!isCompletelyEmpty());
51 BitField & b = LW_FIELDS[m_nonEmptyField];
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
56 assert(firstSetBit<LW_ENTRIESPERGROUP);
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;
64 //Toggle the bit to clear it:
65 assert(b & 1 << firstSetBit);
66 b ^= 1 << firstSetBit;
67 assert( ! (b & 1 << firstSetBit) );
69 const unsigned iEntry(LW_ENTRIESPERGROUP*m_nonEmptyField+firstSetBit);
71 findNewNonEmptyField();
73 assert((m_nonEmptyField==UINT_MAX)==(!m_nUnusedEntries));