]>
Commit | Line | Data |
---|---|---|
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 | ||
9199139f AR |
11 | namespace Ipc |
12 | { | |
d8a82533 | 13 | |
9199139f AR |
14 | namespace Mem |
15 | { | |
d8a82533 | 16 | |
f5eef98c | 17 | /// POSIX shared memory segment |
9199139f AR |
18 | class Segment |
19 | { | |
f5eef98c | 20 | public: |
f1eaa254 | 21 | /// Create a shared memory segment. |
d8a82533 AR |
22 | Segment(const char *const id); |
23 | ~Segment(); | |
f5eef98c | 24 | |
c975f532 DK |
25 | /// Whether shared memory support is available |
26 | static bool Enabled(); | |
27 | ||
15953570 | 28 | /// Create a new shared memory segment. Unlinks the segment on destruction. |
e08b0f77 | 29 | void create(const off_t aSize); |
f5eef98c DK |
30 | void open(); ///< Open an existing shared memory segment. |
31 | ||
32 | const String &name() { return theName; } ///< shared memory segment name | |
e08b0f77 | 33 | off_t size() { return theSize; } ///< shared memory segment size |
2d0647fb | 34 | void *mem() { return reserve(0); } ///< pointer to the next chunk |
937d0d3f | 35 | void *reserve(size_t chunkSize); ///< reserve and return the next chunk |
f5eef98c | 36 | |
c011f9bc | 37 | |
f5eef98c DK |
38 | private: |
39 | void attach(); | |
40 | void detach(); | |
68353d5a | 41 | void unlink(); ///< unlink the segment |
e08b0f77 | 42 | off_t statSize(const char *context) const; |
f5eef98c | 43 | |
9a51593d | 44 | static String GenerateName(const char *id); |
f5eef98c | 45 | |
68353d5a DK |
46 | // not implemented |
47 | Segment(const Segment &); | |
48 | Segment &operator =(const Segment &); | |
49 | ||
f5eef98c DK |
50 | const String theName; ///< shared memory segment file name |
51 | int theFD; ///< shared memory segment file descriptor | |
f5eef98c | 52 | void *theMem; ///< pointer to mmapped shared memory segment |
e08b0f77 AR |
53 | off_t theSize; ///< shared memory segment size |
54 | off_t theReserved; ///< the total number of reserve()d bytes | |
68353d5a | 55 | bool doUnlink; ///< whether the segment should be unlinked on destruction |
f5eef98c DK |
56 | }; |
57 | ||
d8a82533 AR |
58 | } // namespace Mem |
59 | ||
60 | } // namespace Ipc | |
61 | ||
62 | #endif /* SQUID_IPC_MEM_SEGMENT_H */ |