#include "abstract_shared_mem.h"
Public Member Functions | |
virtual size_t | SharedMutexSize () const =0 |
Size of mutexes inside shared memory segments. | |
virtual AbstractSharedMemSegment * | CreateSegment (const GoogleString &name, size_t size, MessageHandler *handler)=0 |
virtual AbstractSharedMemSegment * | AttachToSegment (const GoogleString &name, size_t size, MessageHandler *handler)=0 |
virtual void | DestroySegment (const GoogleString &name, MessageHandler *handler)=0 |
Interface for creating and attaching to named shared memory segments. The expectation is that whichever implementation is used at runtime will be able to handle the combination of threads & processes used by the hosting environment.
The basic flow here is as follows:
Single process/thread startup stage: CreateSegment InitializeSharedMutex -----+ / | / | process/thread: process/thread: AttachToSegment AttachToSegment AttachToSharedMutex AttachToSharedMutex | | | | |------------------------------------/ | single process/thread cleanup stage: DestroySegment
virtual AbstractSharedMemSegment* net_instaweb::AbstractSharedMem::AttachToSegment | ( | const GoogleString & | name, | |
size_t | size, | |||
MessageHandler * | handler | |||
) | [pure virtual] |
Attaches to an existing segment, which must have been created already. May return NULL on failure
Implemented in net_instaweb::NullSharedMem, and net_instaweb::PthreadSharedMem.
virtual AbstractSharedMemSegment* net_instaweb::AbstractSharedMem::CreateSegment | ( | const GoogleString & | name, | |
size_t | size, | |||
MessageHandler * | handler | |||
) | [pure virtual] |
This should be called upon main process/thread initialization to create a shared memory segment that will be accessed by other processes/threads as identified by a unique name (via AttachToSegment). It will remove any previous segment with the same name. The memory will be zeroed out.
May return NULL on failure.
Implemented in net_instaweb::NullSharedMem, and net_instaweb::PthreadSharedMem.
virtual void net_instaweb::AbstractSharedMem::DestroySegment | ( | const GoogleString & | name, | |
MessageHandler * | handler | |||
) | [pure virtual] |
Cleans up the segment with given name. You should call this after there is no longer any need for AttachToSegment to succeed.
Implemented in net_instaweb::NullSharedMem, and net_instaweb::PthreadSharedMem.