Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions
SharedMemPager Class Reference

The shared mempager uses a mutex to protect key access methods. More...

#include <misc.h>

Inheritance diagram for SharedMemPager:
Inheritance graph
[legend]
Collaboration diagram for SharedMemPager:
Collaboration graph
[legend]

Public Member Functions

int getPages (void)
 Return the total number of pages that have been allocated for this memory pool. More...
 
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug. More...
 
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread. More...
 
void enter (void)
 Future abi will use enter/leave/test members. More...
 
void leave (void)
 Future abi will use enter/leave/test members. More...
 
bool test (void)
 Future abi will use enter/leave/test members. More...
 
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread. More...
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread. More...
 

Static Public Member Functions

static void setDebug (bool mode)
 Enable or disable deadlock debugging. More...
 

Protected Member Functions

 SharedMemPager (size_t pagesize=4096, const char *name=NULL)
 Create a mempager mutex pool. More...
 
void purge (void)
 Purge the memory pool while locked. More...
 
void * first (size_t size)
 Get the first memory page after locking. More...
 
void * alloc (size_t size)
 Get the last memory page after locking. More...
 
char * first (char *str)
 Allocate a string from the memory pager pool and copy the string into it's new memory area. More...
 
char * alloc (const char *str)
 Allocate a string from the memory pager pool and copy the string inti it's new memory area. More...
 
void clean (void)
 Clean for memory cleanup before exiting. More...
 

Detailed Description

The shared mempager uses a mutex to protect key access methods.

This class is used when a mempager will be shared by multiple threads.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m mutex protected memory pager.

Definition at line 250 of file misc.h.

Constructor & Destructor Documentation

SharedMemPager::SharedMemPager ( size_t  pagesize = 4096,
const char *  name = NULL 
)
protected

Create a mempager mutex pool.

Parameters
pagesizepage size for allocation.
namea name for the pool.

Member Function Documentation

char* MemPager::alloc ( const char *  str)
protectedinherited

Allocate a string from the memory pager pool and copy the string inti it's new memory area.

This checks only the last active page for available space before allocating a new page.

Parameters
strstring to allocate and copy into paged memory pool.
Returns
copy of string from allocated memory.
void* SharedMemPager::alloc ( size_t  size)
protectedvirtual

Get the last memory page after locking.

Returns
allocated memory space.
Parameters
sizeof request.

Reimplemented from MemPager.

void MemPager::clean ( void  )
protectedinherited

Clean for memory cleanup before exiting.

void Mutex::enter ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Definition at line 263 of file thread.h.

void Mutex::enterMutex ( void  )
inherited

Entering a Mutex locks the mutex for the current thread.

This also can be done using the ENTER_CRITICAL macro or by using the ++ operator on a mutex.

See Also
leaveMutex
char* MemPager::first ( char *  str)
protectedinherited

Allocate a string from the memory pager pool and copy the string into it's new memory area.

This method allocates memory by first searching for an available page, and then allocating a new page if no space is found.

Parameters
strstring to allocate and copy into paged memory pool.
Returns
copy of string from allocated memory.
void* SharedMemPager::first ( size_t  size)
protectedvirtual

Get the first memory page after locking.

Returns
allocated memory space.
Parameters
sizeof request.

Reimplemented from MemPager.

int MemPager::getPages ( void  )
inlineinherited

Return the total number of pages that have been allocated for this memory pool.

Returns
number of pages allocated.

Definition at line 181 of file misc.h.

void Mutex::leave ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Definition at line 269 of file thread.h.

void Mutex::leaveMutex ( void  )
inherited

Leaving a mutex frees that mutex for use by another thread.

If the mutex has been entered (invoked) multiple times (recursivily) by the same thread, then it will need to be exited the same number of instances before it is free for re-use. This operation can also be done using the LEAVE_CRITICAL macro or by the – operator on a mutex.

See Also
enterMutex
void Mutex::nameMutex ( const char *  name)
inlineinherited

Enable setting of mutex name for deadlock debug.

Parameters
namefor mutex.

Definition at line 248 of file thread.h.

void SharedMemPager::purge ( void  )
protected

Purge the memory pool while locked.

static void Mutex::setDebug ( bool  mode)
inlinestaticinherited

Enable or disable deadlock debugging.

Parameters
modedebug mode.

Definition at line 240 of file thread.h.

bool Mutex::test ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Returns
true if entered.

Definition at line 277 of file thread.h.

bool Mutex::tryEnterMutex ( void  )
inherited

Tries to lock the mutex for the current thread.

Behaves like enterMutex , except that it doesn't block the calling thread if the mutex is already locked by another thread.

Returns
true if locking the mutex was succesful otherwise false
See Also
enterMutex
leaveMutex

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