Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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.
void Deallocate (const void *p)
 Deallocate memory claimed by an earlier call to allocate.

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.

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

Definition at line 92 of file ThreadSpecificPool.hpp.

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

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().

{
boost::mutex::scoped_lock l(m_mutex);
void* result = m_pool->malloc();
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
memset(result, 0, m_blockSize);
#endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
return result;
}
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().

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

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().