NAME
ACE_Shared_Memory_Pool -
Make a memory pool that is based on System V shared memory
(shmget(2) etc.). This implementation allows memory to be
shared between processes.
SYNOPSIS
#include <ace/ACE_Memory_Pool.h>
class ACE_Shared_Memory_Pool : public ACE_Event_Handler
{
public:
ACE_Shared_Memory_Pool (
const char *pool_name = ACE_ITOA (ACE_DEFAULT_SHM_KEY)
);
virtual void *init_acquire (
size_t nbytes,
size_t &rounded_bytes,
int &first_time
);
virtual void *acquire (size_t nbytes, size_t &rounded_bytes);
virtual int release (void);
virtual int sync (ssize_t len = -1, int flags = MS_SYNC);
virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
virtual int protect (ssize_t len = -1, int prot = PROT_RDWR);
virtual int protect (
void *addr,
size_t len,
int prot = PROT_RDWR
);
virtual void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
protected:
virtual size_t round_up (size_t nbytes);
virtual int commit_backing_store (
size_t rounded_bytes,
off_t &offset
);
struct SHM_TABLE
{
public:
key_t key;
int shmid;
int used;
};
virtual int in_use (off_t &offset, int &counter);
ACE_Sig_Handler signal_handler_;
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
ACE_SV_Semaphore_Complex init_finished_;
};
PUBLIC MEMBERS
ACE_Shared_Memory_Pool (
const char *pool_name = ACE_ITOA (ACE_DEFAULT_SHM_KEY)
);
Initialization constructor.
virtual void *init_acquire (
size_t nbytes,
size_t &rounded_bytes,
int &first_time
);
Ask system for initial chunk of local memory.
virtual void *acquire (size_t nbytes, size_t &rounded_bytes);
Acquire at least NBYTES from the memory pool. ROUNDED_BYTES is
the actual number of bytes allocated. Also acquires an internal
semaphore that ensures proper serialization of Memory_Pool
initialization across processes.
virtual int release (void);
Instruct the memory pool to release all of its resources.
virtual int sync (ssize_t len = -1, int flags = MS_SYNC);
Sync the memory region to the backing store starting at
this-base_addr_.
virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
Sync the memory region to the backing store starting at addr_.
virtual int protect (ssize_t len = -1, int prot = PROT_RDWR);
Change the protection of the pages of the mapped region to prot
starting at this-base_addr_ up to len bytes. If len == -1
then change protection of all pages in the mapped region.
virtual int protect (void *addr, size_t len, int prot = PROT_RDWR);
Change the protection of the pages of the mapped region to prot
starting at addr up to len bytes.
virtual void dump (void) const;
Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
Declare the dynamic allocation hooks.
PROTECTED MEMBERS
virtual size_t round_up (size_t nbytes);
Implement the algorithm for rounding up the request to an
appropriate chunksize.
virtual int commit_backing_store (
size_t rounded_bytes,
off_t &offset
);
Commits a new shared memory segment if necessary after an
acquire() or a signal. offset is set to the new offset into
the backing store.
virtual int in_use (off_t &offset, int &counter);
Determine how much memory is currently in use.
ACE_Sig_Handler signal_handler_;
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
Handle SIGSEGV and SIGBUS signals to remap shared memory
properly.
ACE_SV_Semaphore_Complex init_finished_;
Used to serialize initialization of the Memory_Pool and Malloc.
AUTHOR
Doug Schmidt and Prashant Jain
LIBRARY
ace