]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/Segment.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_IPC_MEM_SEGMENT_H
10 #define SQUID_IPC_MEM_SEGMENT_H
12 #include "base/RunnersRegistry.h"
13 #include "SquidString.h"
23 /// POSIX shared memory segment
27 /// Create a shared memory segment.
28 Segment(const char *const id
);
31 /// Whether shared memory support is available
32 static bool Enabled();
34 /// Create a new shared memory segment. Unlinks the segment on destruction.
35 void create(const off_t aSize
);
36 void open(); ///< Open an existing shared memory segment.
38 const String
&name() { return theName
; } ///< shared memory segment name
39 off_t
size() { return theSize
; } ///< shared memory segment size
40 void *mem() { return reserve(0); } ///< pointer to the next chunk
41 void *reserve(size_t chunkSize
); ///< reserve and return the next chunk
43 /// common path of all segment names in path-based environments
44 static const char *BasePath
;
46 /// concatenates parts of a name to form a complete name (or its prefix)
47 static SBuf
Name(const SBuf
&prefix
, const char *suffix
);
52 Segment(const Segment
&);
53 Segment
&operator =(const Segment
&);
59 void unlink(); ///< unlink the segment
60 off_t
statSize(const char *context
) const;
62 static String
GenerateName(const char *id
);
64 int theFD
; ///< shared memory segment file descriptor
68 void checkSupport(const char *const context
);
72 const String theName
; ///< shared memory segment file name
73 void *theMem
; ///< pointer to mmapped shared memory segment
74 off_t theSize
; ///< shared memory segment size
75 off_t theReserved
; ///< the total number of reserve()d bytes
76 bool doUnlink
; ///< whether the segment should be unlinked on destruction
79 /// Base class for runners that create and open shared memory segments.
80 /// First may run create() method and then open().
81 class RegisteredRunner
: public ::RegisteredRunner
84 /* RegisteredRunner API */
85 virtual void useConfig();
88 /// called when the runner should create a new memory segment
89 virtual void create() = 0;
90 /// called when the runner should open a previously created segment,
91 /// not needed if segments are opened in constructor or init methods
92 virtual void open() {}
99 #endif /* SQUID_IPC_MEM_SEGMENT_H */