]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/mem/Segment.h
Polished comments.
[thirdparty/squid.git] / src / ipc / mem / Segment.h
CommitLineData
f5eef98c
DK
1/*
2 * $Id$
3 *
4 */
5
d8a82533
AR
6#ifndef SQUID_IPC_MEM_SEGMENT_H
7#define SQUID_IPC_MEM_SEGMENT_H
f5eef98c
DK
8
9#include "SquidString.h"
10
d8a82533
AR
11namespace Ipc {
12
13namespace Mem {
14
f5eef98c 15/// POSIX shared memory segment
d8a82533 16class Segment {
f5eef98c 17public:
f1eaa254 18 /// Create a shared memory segment.
d8a82533
AR
19 Segment(const char *const id);
20 ~Segment();
f5eef98c 21
c975f532
DK
22 /// Whether shared memory support is available
23 static bool Enabled();
24
f5eef98c 25 /// Create a new shared memory segment. Fails if a segment with
68353d5a 26 /// the same name already exists. Unlinks the segment on destruction.
e08b0f77 27 void create(const off_t aSize);
f5eef98c
DK
28 void open(); ///< Open an existing shared memory segment.
29
30 const String &name() { return theName; } ///< shared memory segment name
e08b0f77 31 off_t size() { return theSize; } ///< shared memory segment size
2d0647fb 32 void *mem() { return reserve(0); } ///< pointer to the next chunk
937d0d3f 33 void *reserve(size_t chunkSize); ///< reserve and return the next chunk
f5eef98c 34
c011f9bc 35
f5eef98c
DK
36private:
37 void attach();
38 void detach();
68353d5a 39 void unlink(); ///< unlink the segment
e08b0f77 40 off_t statSize(const char *context) const;
f5eef98c 41
9a51593d 42 static String GenerateName(const char *id);
f5eef98c 43
68353d5a
DK
44 // not implemented
45 Segment(const Segment &);
46 Segment &operator =(const Segment &);
47
f5eef98c
DK
48 const String theName; ///< shared memory segment file name
49 int theFD; ///< shared memory segment file descriptor
f5eef98c 50 void *theMem; ///< pointer to mmapped shared memory segment
e08b0f77
AR
51 off_t theSize; ///< shared memory segment size
52 off_t theReserved; ///< the total number of reserve()d bytes
68353d5a 53 bool doUnlink; ///< whether the segment should be unlinked on destruction
f5eef98c
DK
54};
55
d8a82533
AR
56} // namespace Mem
57
58} // namespace Ipc
59
60#endif /* SQUID_IPC_MEM_SEGMENT_H */