9#ifndef SQUID_IPC_MEM_POINTER_H
10#define SQUID_IPC_MEM_POINTER_H
30 static Owner *
New(
const char *
const id,
const P1 &p1);
31 template <
class P1,
class P2>
32 static Owner *
New(
const char *
const id,
const P1 &p1,
const P2 &p2);
33 template <
class P1,
class P2,
class P3>
34 static Owner *
New(
const char *
const id,
const P1 &p1,
const P2 &p2,
const P3 &p3);
35 template <
class P1,
class P2,
class P3,
class P4>
36 static Owner *
New(
const char *
const id,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4);
46 explicit Owner(
const char *
const id);
47 Owner(
const char *
const id,
const off_t sharedSize);
57template <
class Class>
class Pointer;
67 explicit Object(
const char *
const id);
100 theSegment(id), theObject(nullptr)
106template <
class Class>
108 theSegment(id), theObject(nullptr)
114template <
class Class>
121template <
class Class>
125 auto owner =
new Owner(
id);
126 owner->theObject =
reinterpret_cast<Class*
>(owner->theSegment.mem());
127 Must(
static_cast<off_t
>(owner->theObject->sharedMemorySize()) <= owner->theSegment.size());
131template <
class Class>
135 const off_t sharedSize = Class::SharedMemorySize();
136 Owner *
const owner =
new Owner(
id, sharedSize);
141template <
class Class>
template <
class P1>
145 const off_t sharedSize = Class::SharedMemorySize(p1);
146 Owner *
const owner =
new Owner(
id, sharedSize);
151template <
class Class>
template <
class P1,
class P2>
155 const off_t sharedSize = Class::SharedMemorySize(p1, p2);
156 Owner *
const owner =
new Owner(
id, sharedSize);
161template <
class Class>
template <
class P1,
class P2,
class P3>
165 const off_t sharedSize = Class::SharedMemorySize(p1, p2, p3);
166 Owner *
const owner =
new Owner(
id, sharedSize);
171template <
class Class>
template <
class P1,
class P2,
class P3,
class P4>
175 const off_t sharedSize = Class::SharedMemorySize(p1, p2, p3, p4);
176 Owner *
const owner =
new Owner(
id, sharedSize);
183template <
class Class>
192template <
class Class>
200#define shm_new(Class) Ipc::Mem::Owner<Class>::New
201#define shm_old(Class) Ipc::Mem::Object<Class>::Old
#define RefCountable
The locking interface for use on Reference-Counted classes.
attaches to a shared memory segment with Class object owned by Owner
Object & operator=(const Object &)
Segment theSegment
shared memory segment that holds the object
static Pointer< Class > Old(const char *const id)
Class * theObject
shared object
Object(const char *const id)
Owner(const char *const id)
Owner(const char *const id, const off_t sharedSize)
Class * theObject
shared object
static Owner * New(const char *const id)
Segment theSegment
shared memory segment that holds the object
static Owner * New(const char *const id, const P1 &p1, const P2 &p2)
static Owner * New(const char *const id, const P1 &p1)
Owner & operator=(const Owner &)
Class * object()
Raw access; handy to finalize initiatization, but avoid if possible.
static Owner * Old(const char *const id)
attaches to the existing shared memory segment, becoming its owner
static Owner * New(const char *const id, const P1 &p1, const P2 &p2, const P3 &p3)
static Owner * New(const char *const id, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
Class & operator*() const
const Class * getRaw() const
RefCount< Object< Class > > Base
Pointer(Object< Class > *const anObject=nullptr)
Class * operator->() const
POSIX shared memory segment.
void open(const bool unlinkWhenDone)
void * mem()
pointer to the next chunk
void * reserve(size_t chunkSize)
reserve and return the next chunk
void create(const off_t aSize)
Create a new shared memory segment. Unlinks the segment on destruction.
off_t size()
shared memory segment size
Object< Class > * operator->() const
Object< Class > * getRaw() const
Object< Class > & operator*() const