Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Private Attributes | List of all members
Nektar::detail::ThreadSpecificPool Class Reference

#include <ThreadSpecificPool.hpp>

Public Member Functions

 ThreadSpecificPool (size_t ByteSize)
 
 ~ThreadSpecificPool ()
 
voidAllocate ()
 Allocate a block of memory of size ByteSize. More...
 
void Deallocate (const void *p)
 Deallocate memory claimed by an earlier call to allocate. More...
 

Private Attributes

boost::pool * m_pool
 
size_t m_blockSize
 
boost::mutex m_mutex
 

Detailed Description

Definition at line 79 of file ThreadSpecificPool.hpp.

Constructor & Destructor Documentation

Nektar::detail::ThreadSpecificPool::ThreadSpecificPool ( size_t  ByteSize)
inline

Definition at line 82 of file ThreadSpecificPool.hpp.

References m_blockSize, and m_pool.

82  :
83  m_pool(),
84  m_blockSize(ByteSize),
85  m_mutex()
86  {
87  // We can do the new in the constructor list because the thread specific
88  // pointer doesn't have a supporting constructor.
89  m_pool = new boost::pool<>(m_blockSize);
90  }
Nektar::detail::ThreadSpecificPool::~ThreadSpecificPool ( )
inline

Definition at line 92 of file ThreadSpecificPool.hpp.

93  {
94  // The documentation isn't particularly clear if delete needs to be called manually
95  // or if the thread specific pointer will call delete for me. Looking through the
96  // boost code doesn't make it any clearer.
97  }

Member Function Documentation

void* Nektar::detail::ThreadSpecificPool::Allocate ( )
inline

Allocate a block of memory of size ByteSize.

Exceptions
std::bad_allocif memory is exhausted.

Definition at line 101 of file ThreadSpecificPool.hpp.

References m_blockSize, m_mutex, and m_pool.

Referenced by Nektar::MemPool::Allocate().

102  {
103  boost::mutex::scoped_lock l(m_mutex);
104  void* result = m_pool->malloc();
105 
106 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
107  memset(result, 0, m_blockSize);
108 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
109 
110  return result;
111  }
void Nektar::detail::ThreadSpecificPool::Deallocate ( const void p)
inline

Deallocate memory claimed by an earlier call to allocate.

Attention
It is an error to deallocate memory not allocated from this pool. Doing this will result in undefined behavior.

Definition at line 117 of file ThreadSpecificPool.hpp.

References m_mutex, and m_pool.

Referenced by Nektar::MemPool::Deallocate().

118  {
119  boost::mutex::scoped_lock l(m_mutex);
120 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
121  // The idea here is to fill the returned memory with some known
122  // pattern, then detect that pattern on the allocate. If the
123  // pattern is no longer there then some memory corruption has
124  // occurred. However, I'm not sure how to distinguish between first
125  // time allocations and repeat allocations.
126 
127  //memset(p, '+', m_pool->get_requested_size());
128 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
129 
130  m_pool->free(const_cast<void*>(p));
131  }

Member Data Documentation

size_t Nektar::detail::ThreadSpecificPool::m_blockSize
private

Definition at line 137 of file ThreadSpecificPool.hpp.

Referenced by Allocate(), and ThreadSpecificPool().

boost::mutex Nektar::detail::ThreadSpecificPool::m_mutex
private

Definition at line 138 of file ThreadSpecificPool.hpp.

Referenced by Allocate(), and Deallocate().

boost::pool* Nektar::detail::ThreadSpecificPool::m_pool
private

Definition at line 136 of file ThreadSpecificPool.hpp.

Referenced by Allocate(), Deallocate(), and ThreadSpecificPool().