ATLAS Offline Software
LWPool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Header file for class LWPool //
9 // //
10 // Description: ... //
11 // //
12 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
13 // Initial version: April 2009 //
14 // //
16 
17 #ifndef LWPOOL_H
18 #define LWPOOL_H
19 
20 #include "LWPoolArea.h"
21 #include <vector>
22 #include <mutex>
23 
24 class LWPool {
25 public:
26 
27  LWPool(unsigned chunksize);
28  ~LWPool();
29 
30  char* acquire();
31  char* acquireClean();//Same as acquire(), but zeroes out the acquired memory
32  void release(char* );
33  void erase();
34 
35  long long getMemDishedOut() const;
36  long long getMemOwned() const;
37  static long long getMotherMemOwned();
38  static void forceCleanupMotherPool();
39 private:
40  const unsigned m_chunksize;
41  const unsigned m_growsize;
42  unsigned m_nchunksPerArea;
43  std::vector<LWPoolArea*> m_areas;
44  LWPoolArea* m_likelyNonEmptyArea;//A good guess of where to find available chunks.
45  LWPoolArea* m_likelyReleaseArea;//Last ::release(..) was to this area.
47 
48 private:
49  LWPool( const LWPool & );
50  LWPool & operator= ( const LWPool & );
51  LWPoolArea* grow();//Returns fresh area
52  void freeArea(LWPoolArea*);//invalidates iterators
53  unsigned growSize() const { return m_growsize; }
54  unsigned chunkSize() const { return m_chunksize; }
55  void init();
56  bool belongsInArea(char*,LWPoolArea*) const;
57 private:
58  static LWPool * getMotherPool();
59  char * searchAcquire();//goes through all areas until something is acquired.
60  LWPoolArea* findArea(char*);//binary search for correct area
61  bool isMotherPool() const { return this==getMotherPool(); }
62  LWPool(unsigned chunksize,unsigned growsize);//Becomes a mother mem-pool (bool parameter
63  //is just to trigger this constructor.
64 };
65 
66 #include "LWPool.icc"
67 
68 //For debugging allocations:
69 #ifdef LWHISTMALLOCDEBUG
70 #include <iostream>
71 #define LWHISTMALLOC(s) {std::cout<<"LWHISTMALLOC "<<__FILE__<<":"<<__LINE__<<" : "<<s<<" bytes"<<std::endl;}
72 #else
73 #define LWHISTMALLOC(s) {}
74 #endif
75 
76 #endif
LWPool::operator=
LWPool & operator=(const LWPool &)
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
LWPool::freeArea
void freeArea(LWPoolArea *)
Definition: LWPool.cxx:174
LWPool::growSize
unsigned growSize() const
Definition: LWPool.h:53
LWPool::searchAcquire
char * searchAcquire()
Definition: LWPool.cxx:113
LWPool::m_likelyNonEmptyArea
LWPoolArea * m_likelyNonEmptyArea
Definition: LWPool.h:44
LWPool::getMemDishedOut
long long getMemDishedOut() const
Definition: LWPool.cxx:96
LWPool::findArea
LWPoolArea * findArea(char *)
Definition: LWPool.cxx:131
LWPool::getMemOwned
long long getMemOwned() const
Definition: LWPool.cxx:89
LWPool::forceCleanupMotherPool
static void forceCleanupMotherPool()
Definition: LWPool.cxx:206
LWPool::m_nchunksPerArea
unsigned m_nchunksPerArea
Definition: LWPool.h:42
LWPool::acquire
char * acquire()
LWPool::grow
LWPoolArea * grow()
Definition: LWPool.cxx:147
LWPoolArea.h
LWPool::init
void init()
Definition: LWPool.cxx:50
LWPool::chunkSize
unsigned chunkSize() const
Definition: LWPool.h:54
LWPool::m_growsize
const unsigned m_growsize
Definition: LWPool.h:41
LWPool::getMotherPool
static LWPool * getMotherPool()
Definition: LWPool.cxx:20
LWPool::acquireClean
char * acquireClean()
Definition: LWPool.cxx:105
LWPool.icc
LWPoolArea
Definition: LWPoolArea.h:25
LWPool::m_areas
std::vector< LWPoolArea * > m_areas
Definition: LWPool.h:43
LWPool::release
void release(char *)
LWPool::belongsInArea
bool belongsInArea(char *, LWPoolArea *) const
LWPool::m_chunksize
const unsigned m_chunksize
Definition: LWPool.h:40
LWPool::isMotherPool
bool isMotherPool() const
Definition: LWPool.h:61
LWPool::LWPool
LWPool(unsigned chunksize)
Definition: LWPool.cxx:32
LWPool
Definition: LWPool.h:24
LWPool::~LWPool
~LWPool()
Definition: LWPool.cxx:61
LWPool::LWPool
LWPool(const LWPool &)
LWPool::m_mutex
std::mutex m_mutex
Definition: LWPool.h:46
LWPool::erase
void erase()
Definition: LWPool.cxx:67
LWPool::m_likelyReleaseArea
LWPoolArea * m_likelyReleaseArea
Definition: LWPool.h:45
LWPool::getMotherMemOwned
static long long getMotherMemOwned()
Definition: LWPool.cxx:83