]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/Segment.h
4 #ifndef SQUID_IPC_MEM_SEGMENT_H
5 #define SQUID_IPC_MEM_SEGMENT_H
7 #include "base/RunnersRegistry.h"
8 #include "SquidString.h"
16 /// POSIX shared memory segment
20 /// Create a shared memory segment.
21 Segment(const char *const id
);
24 /// Whether shared memory support is available
25 static bool Enabled();
27 /// Create a new shared memory segment. Unlinks the segment on destruction.
28 void create(const off_t aSize
);
29 void open(); ///< Open an existing shared memory segment.
31 const String
&name() { return theName
; } ///< shared memory segment name
32 off_t
size() { return theSize
; } ///< shared memory segment size
33 void *mem() { return reserve(0); } ///< pointer to the next chunk
34 void *reserve(size_t chunkSize
); ///< reserve and return the next chunk
36 /// common path of all segment names in path-based environments
37 static const char *BasePath
;
42 Segment(const Segment
&);
43 Segment
&operator =(const Segment
&);
49 void unlink(); ///< unlink the segment
50 off_t
statSize(const char *context
) const;
52 static String
GenerateName(const char *id
);
54 int theFD
; ///< shared memory segment file descriptor
58 void checkSupport(const char *const context
);
62 const String theName
; ///< shared memory segment file name
63 void *theMem
; ///< pointer to mmapped shared memory segment
64 off_t theSize
; ///< shared memory segment size
65 off_t theReserved
; ///< the total number of reserve()d bytes
66 bool doUnlink
; ///< whether the segment should be unlinked on destruction
69 /// Base class for runners that create and open shared memory segments.
70 /// First may run create() method and then open().
71 class RegisteredRunner
: public ::RegisteredRunner
74 /* RegisteredRunner API */
75 virtual void useConfig();
78 /// called when the runner should create a new memory segment
79 virtual void create() = 0;
80 /// called when the runner should open a previously created segment,
81 /// not needed if segments are opened in constructor or init methods
82 virtual void open() {}
89 #endif /* SQUID_IPC_MEM_SEGMENT_H */