ATLAS Offline Software
LWPoolArea.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 inline LWPoolArea* LWPoolArea::create( unsigned chunksize,
6  char* mem,
7  unsigned length_of_mem,
8  unsigned nchunks )
9 {
10  assert(length_of_mem>sizeof(LWPoolArea)+sizeof(LWPoolAreaBookKeeper));
11 #ifndef NDEBUG
12  //Allow valgrind to spot problems:
13  mem[0]='A';
14  mem[length_of_mem-1]='A';
15 #endif
16  return new(mem) LWPoolArea(chunksize,( nchunks==UINT_MAX
17  ? LWPoolArea::calcNChunks(chunksize,length_of_mem)
18  : nchunks));
19 }
20 
21 inline LWPoolArea::LWPoolArea(unsigned chunksize,unsigned nchunks)
22  : m_chunksize(chunksize),
23  m_nchunks(nchunks),
24  m_bookkeep(LWPoolAreaBookKeeper::create(reinterpret_cast<char*>(this)+sizeof(*this),nchunks)),
25  m_area(reinterpret_cast<char*>(m_bookkeep)+m_bookkeep->nBytesCovered())
26 {
27 }
28 
29 inline char* LWPoolArea::acquire()
30 {
31  const unsigned index = m_bookkeep->acquireEntry();
32  return index==UINT_MAX ? 0 : m_area + m_chunksize * index;
33 }
34 
35 inline void LWPoolArea::release(char*c)
36 {
37  assert((c-m_area)%m_chunksize==0);
38  m_bookkeep->returnEntry((c-m_area)/m_chunksize);
39 }
40 
41 inline bool LWPoolArea::isUnused() const
42 {
43  return m_bookkeep->isCompletelyFull();
44 
45 }
46 
47 inline long long LWPoolArea::getMemDishedOut() const
48 {
49  return static_cast<long long>(m_bookkeep->numberOfEntriesHandedOut())*m_chunksize;
50 }
51 
52 #ifndef NDEBUG
53 inline long long LWPoolArea::getMemUnusedButAllocated() const
54 {
55  return m_bookkeep->numberOfAvailableEntries()*m_chunksize;
56 }
57 
58 inline bool LWPoolArea::belongsInArea(char*c) const
59 {
60  //Not the fastest in principle due to the multiplication and addition:
61  return m_area<=c && c < (m_area+(m_nchunks*m_chunksize));
62 }
63 #endif