]>
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 | 38 | private: |
be9cb908 DK |
39 | |
40 | // not implemented | |
41 | Segment(const Segment &); | |
42 | Segment &operator =(const Segment &); | |
43 | ||
44 | #if HAVE_SHM | |
45 | ||
f5eef98c DK |
46 | void attach(); |
47 | void detach(); | |
68353d5a | 48 | void unlink(); ///< unlink the segment |
e08b0f77 | 49 | off_t statSize(const char *context) const; |
f5eef98c | 50 | |
9a51593d | 51 | static String GenerateName(const char *id); |
f5eef98c | 52 | |
be9cb908 DK |
53 | int theFD; ///< shared memory segment file descriptor |
54 | ||
55 | #else // HAVE_SHM | |
56 | ||
57 | void checkSupport(const char *const context); | |
58 | ||
59 | #endif // HAVE_SHM | |
68353d5a | 60 | |
f5eef98c | 61 | const String theName; ///< shared memory segment file name |
f5eef98c | 62 | void *theMem; ///< pointer to mmapped shared memory segment |
e08b0f77 AR |
63 | off_t theSize; ///< shared memory segment size |
64 | off_t theReserved; ///< the total number of reserve()d bytes | |
68353d5a | 65 | bool doUnlink; ///< whether the segment should be unlinked on destruction |
f5eef98c DK |
66 | }; |
67 | ||
d8a82533 AR |
68 | } // namespace Mem |
69 | ||
70 | } // namespace Ipc | |
71 | ||
72 | #endif /* SQUID_IPC_MEM_SEGMENT_H */ |