PRCYCoin  2.0.0.7rc1
P2P Digital Currency
Public Member Functions | Private Types | Private Attributes | List of all members
LockedPageManagerBase< Locker > Class Template Reference

Thread-safe class to keep track of locked (ie, non-swappable) memory pages. More...

#include <allocators.h>

Public Member Functions

 LockedPageManagerBase (size_t page_size)
 
 ~LockedPageManagerBase ()
 
void LockRange (void *p, size_t size)
 
void UnlockRange (void *p, size_t size)
 
int GetLockedPageCount ()
 

Private Types

typedef std::map< size_t, int > Histogram
 

Private Attributes

Locker locker
 
boost::mutex mutex
 
size_t page_size
 
size_t page_mask
 
Histogram histogram
 

Detailed Description

template<class Locker>
class LockedPageManagerBase< Locker >

Thread-safe class to keep track of locked (ie, non-swappable) memory pages.

Memory locks do not stack, that is, pages which have been locked several times by calls to mlock() will be unlocked by a single call to munlock(). This can result in keying material ending up in swap when those functions are used naively. This class simulates stacking memory locks by keeping a counter per page.

Note
By using a map from each page base address to lock count, this class is optimized for small objects that span up to a few pages, mostly smaller than a page. To support large allocations, something like an interval tree would be the preferred data structure.

Definition at line 31 of file allocators.h.

Member Typedef Documentation

◆ Histogram

template<class Locker >
typedef std::map<size_t, int> LockedPageManagerBase< Locker >::Histogram
private

Definition at line 103 of file allocators.h.

Constructor & Destructor Documentation

◆ LockedPageManagerBase()

template<class Locker >
LockedPageManagerBase< Locker >::LockedPageManagerBase ( size_t  page_size)
inline

Definition at line 34 of file allocators.h.

◆ ~LockedPageManagerBase()

template<class Locker >
LockedPageManagerBase< Locker >::~LockedPageManagerBase ( )
inline

Definition at line 41 of file allocators.h.

Member Function Documentation

◆ GetLockedPageCount()

template<class Locker >
int LockedPageManagerBase< Locker >::GetLockedPageCount ( )
inline

Definition at line 92 of file allocators.h.

◆ LockRange()

template<class Locker >
void LockedPageManagerBase< Locker >::LockRange ( void *  p,
size_t  size 
)
inline

Definition at line 47 of file allocators.h.

Here is the caller graph for this function:

◆ UnlockRange()

template<class Locker >
void LockedPageManagerBase< Locker >::UnlockRange ( void *  p,
size_t  size 
)
inline

Definition at line 69 of file allocators.h.

Here is the caller graph for this function:

Member Data Documentation

◆ histogram

template<class Locker >
Histogram LockedPageManagerBase< Locker >::histogram
private

Definition at line 104 of file allocators.h.

◆ locker

template<class Locker >
Locker LockedPageManagerBase< Locker >::locker
private

Definition at line 99 of file allocators.h.

◆ mutex

template<class Locker >
boost::mutex LockedPageManagerBase< Locker >::mutex
private

Definition at line 100 of file allocators.h.

◆ page_mask

template<class Locker >
size_t LockedPageManagerBase< Locker >::page_mask
private

Definition at line 101 of file allocators.h.

◆ page_size

template<class Locker >
size_t LockedPageManagerBase< Locker >::page_size
private

Definition at line 101 of file allocators.h.


The documentation for this class was generated from the following file: