Segment.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_IPC_MEM_SEGMENT_H
10#define SQUID_IPC_MEM_SEGMENT_H
11
13#include "sbuf/forward.h"
14#include "SquidString.h"
15
16namespace Ipc
17{
18
19namespace Mem
20{
21
24{
25public:
27 Segment(const char *const id);
28 ~Segment();
29
31 static bool Enabled();
32
34 void create(const off_t aSize);
37 void open(const bool unlinkWhenDone);
38
39 const String &name() { return theName; }
40 off_t size() { return theSize; }
41 void *mem() { return reserve(0); }
42 void *reserve(size_t chunkSize);
43
45 static const char *BasePath;
46
48 static SBuf Name(const SBuf &prefix, const char *suffix);
49
50private:
51
52 // not implemented
53 Segment(const Segment &);
55
56#if HAVE_SHM
57
58 bool createFresh(int &err);
59 void attach();
60 void detach();
61 void lock();
62 void unlink();
63 off_t statSize(const char *context) const;
64
65 static String GenerateName(const char *id);
66
67 int theFD;
68
69#else // HAVE_SHM
70
71 void checkSupport(const char *const context);
72
73#endif // HAVE_SHM
74
76 void *theMem;
77 off_t theSize;
79 bool doUnlink;
80};
81
85{
86public:
87 /* RegisteredRunner API */
88 void useConfig() override;
89
90protected:
92 virtual void create() = 0;
95 virtual void open() {}
96};
97
98} // namespace Mem
99
100} // namespace Ipc
101
102#endif /* SQUID_IPC_MEM_SEGMENT_H */
103
void useConfig() override
Definition: Segment.cc:377
virtual void create()=0
called when the runner should create a new memory segment
virtual void open()
Definition: Segment.h:95
POSIX shared memory segment.
Definition: Segment.h:24
bool doUnlink
whether the segment should be unlinked on destruction
Definition: Segment.h:79
off_t theReserved
the total number of reserve()d bytes
Definition: Segment.h:78
Segment & operator=(const Segment &)
off_t theSize
shared memory segment size
Definition: Segment.h:77
void open(const bool unlinkWhenDone)
Definition: Segment.cc:346
static const char * BasePath
common path of all segment names in path-based environments
Definition: Segment.h:45
static bool Enabled()
Whether shared memory support is available.
Definition: Segment.cc:322
void * mem()
pointer to the next chunk
Definition: Segment.h:41
static SBuf Name(const SBuf &prefix, const char *suffix)
concatenates parts of a name to form a complete name (or its prefix)
Definition: Segment.cc:52
void * theMem
pointer to mmapped shared memory segment
Definition: Segment.h:76
void * reserve(size_t chunkSize)
reserve and return the next chunk
Definition: Segment.cc:38
const String theName
shared memory segment file name
Definition: Segment.h:75
Segment(const char *const id)
Create a shared memory segment.
Definition: Segment.cc:306
void checkSupport(const char *const context)
Definition: Segment.cc:363
Segment(const Segment &)
void create(const off_t aSize)
Create a new shared memory segment. Unlinks the segment on destruction.
Definition: Segment.cc:328
off_t size()
shared memory segment size
Definition: Segment.h:40
const String & name()
shared memory segment name
Definition: Segment.h:39
Definition: SBuf.h:94
Definition: IpcIoFile.h:24
Memory Management.
Definition: Allocator.h:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors