]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Moved ipc/SharedMemory to ipc/mem/ and renamed it to Ipc::Mem::Segment.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 31 Mar 2011 21:22:12 +0000 (15:22 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 31 Mar 2011 21:22:12 +0000 (15:22 -0600)
All IPC things are "shared" by default.

The new name is also more specific because there are other shared memory
structures such as queues and stacks (all using shared memory segments
internally though).

src/fs/rock/RockDirMap.h
src/ipc/Makefile.am
src/ipc/Queue.h
src/ipc/mem/PageStack.h
src/ipc/mem/Segment.cc [moved from src/ipc/SharedMemory.cc with 62% similarity]
src/ipc/mem/Segment.h [moved from src/ipc/SharedMemory.h with 78% similarity]

index 9e71f3dd314256ef0c3312f7c92536de4fe6f06f..6317e61aa91db8ba491e2afedd4456742e217f42 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "fs/rock/RockFile.h"
 #include "ipc/AtomicWord.h"
-#include "ipc/SharedMemory.h"
+#include "ipc/mem/Segment.h"
 
 namespace Rock {
 
@@ -137,7 +137,7 @@ private:
     static int SharedSize(const int limit);
 
     const String path; ///< cache_dir path, used for logging
-    SharedMemory shm; ///< shared memory segment
+    Ipc::Mem::Segment shm; ///< shared memory segment
     Shared *shared; ///< pointer to shared memory
 };
 
index d1bca5272ece70b7b06b87325b84ed8856a3bebd..8550cb76b881deaddffe76b06b3e1a3ea0698dfe 100644 (file)
@@ -23,8 +23,6 @@ libipc_la_SOURCES = \
        StrandSearch.h \
        SharedListen.cc \
        SharedListen.h \
-       SharedMemory.cc \
-       SharedMemory.h \
        TypedMsgHdr.cc \
        TypedMsgHdr.h \
        Coordinator.cc \
@@ -39,6 +37,8 @@ libipc_la_SOURCES = \
        forward.h \
        \
        mem/PageStack.cc \
-       mem/PageStack.h
+       mem/PageStack.h \
+       mem/Segment.cc \
+       mem/Segment.h
 
 DEFS += -DDEFAULT_PREFIX=\"$(prefix)\"
index c3b4b42913352fa481afdf225c257a6347093e6d..ff62eac462b2b0a1bec69715e4bef48858ef69cb 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "Array.h"
 #include "ipc/AtomicWord.h"
-#include "ipc/SharedMemory.h"
+#include "ipc/mem/Segment.h"
 #include "util.h"
 
 class String;
@@ -52,7 +52,7 @@ private:
         char theBuffer[];
     };
 
-    SharedMemory shm; ///< shared memory segment
+    Ipc::Mem::Segment shm; ///< shared memory segment
     Shared *shared; ///< pointer to shared memory
 };
 
index 6cc1842c90beecc78224e78a0108232ca4860adb..ae3b9b0712f6629d59e28020abebfa2a3a3f2a22 100644 (file)
@@ -7,7 +7,7 @@
 #define SQUID_IPC_MEM_PAGE_STACK_H
 
 #include "ipc/AtomicWord.h"
-#include "ipc/SharedMemory.h"
+#include "ipc/mem/Segment.h"
 
 namespace Ipc {
 
@@ -53,7 +53,7 @@ private:
         Item theItems[]; ///< page number storage
     };
 
-    SharedMemory shm; ///< shared memory segment to store metadata (and pages)
+    Segment shm; ///< shared memory segment to store metadata (and pages)
     Shared *shared; ///< our metadata, shared among all stack users
 };
 
similarity index 62%
rename from src/ipc/SharedMemory.cc
rename to src/ipc/mem/Segment.cc
index 22633b12eec8506b084648e5fda05bcec69f42fc..d677505f695e361647c2479d457cfd28bb43f54d 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "config.h"
 
-#include "ipc/SharedMemory.h"
+#include "ipc/mem/Segment.h"
 #include "protos.h"
 
 #include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-SharedMemory::SharedMemory(const char *const id):
+Ipc::Mem::Segment::Segment(const char *const id):
     theName(GenerateName(id)), theFD(-1), theSize(-1), theMem(NULL)
 {
 }
 
-SharedMemory::~SharedMemory() {
+Ipc::Mem::Segment::~Segment() {
     if (theFD >= 0) {
         detach();
-        if (close(theFD))
-            debugs(54, 5, "SharedMemory::~SharedMemory: close: " << xstrerror());
+        if (close(theFD) != 0)
+            debugs(54, 5, HERE << "close: " << xstrerror());
     }
 }
 
 void
-SharedMemory::create(const int aSize)
+Ipc::Mem::Segment::create(const int aSize)
 {
     assert(aSize > 0);
     assert(theFD < 0);
@@ -38,13 +38,13 @@ SharedMemory::create(const int aSize)
     theFD = shm_open(theName.termedBuf(), O_CREAT | O_RDWR | O_TRUNC,
                      S_IRUSR | S_IWUSR);
     if (theFD < 0) {
-        debugs(54, 5, "SharedMemory::create: shm_open: " << xstrerror());
-        fatal("SharedMemory::create failed");
+        debugs(54, 5, HERE << "shm_open: " << xstrerror());
+        fatal("Ipc::Mem::Segment::create failed to shm_open");
     }
 
     if (ftruncate(theFD, aSize)) {
-        debugs(54, 5, "SharedMemory::create: ftruncate: " << xstrerror());
-        fatal("SharedMemory::create failed");
+        debugs(54, 5, HERE << "ftruncate: " << xstrerror());
+        fatal("Ipc::Mem::Segment::create failed to ftruncate");
     }
 
     theSize = aSize;
@@ -53,14 +53,14 @@ SharedMemory::create(const int aSize)
 }
 
 void
-SharedMemory::open()
+Ipc::Mem::Segment::open()
 {
     assert(theFD < 0);
 
     theFD = shm_open(theName.termedBuf(), O_RDWR, 0);
     if (theFD < 0) {
-        debugs(54, 5, "SharedMemory::open: shm_open: " << xstrerror());
-        String s = "SharedMemory::open failed 1 ";
+        debugs(54, 5, HERE << "shm_open: " << xstrerror());
+        String s = "Ipc::Mem::Segment::open failed to shm_open";
         s.append(theName);
         fatal(s.termedBuf());
     }
@@ -69,8 +69,8 @@ SharedMemory::open()
         struct stat s;
         memset(&s, 0, sizeof(s));
         if (fstat(theFD, &s)) {
-            debugs(54, 5, "SharedMemory::open: fstat: " << xstrerror());
-        String s = "SharedMemory::open failed 2 ";
+            debugs(54, 5, HERE << "fstat: " << xstrerror());
+        String s = "Ipc::Mem::Segment::open failed to fstat";
         s.append(theName);
         fatal(s.termedBuf());
         }
@@ -83,7 +83,7 @@ SharedMemory::open()
 
 /// Map the shared memory segment to the process memory space.
 void
-SharedMemory::attach()
+Ipc::Mem::Segment::attach()
 {
     assert(theFD >= 0);
     assert(theSize >= 0);
@@ -92,29 +92,29 @@ SharedMemory::attach()
     void *const p =
         mmap(NULL, theSize, PROT_READ | PROT_WRITE, MAP_SHARED, theFD, 0);
     if (p == MAP_FAILED) {
-        debugs(54, 5, "SharedMemory::mmap: mmap: " << xstrerror());
-        fatal("SharedMemory::mmap failed");
+        debugs(54, 5, HERE << "mmap: " << xstrerror());
+        fatal("Ipc::Mem::Segment::attach failed to mmap");
     }
     theMem = p;
 }
 
 /// Unmap the shared memory segment from the process memory space.
 void
-SharedMemory::detach()
+Ipc::Mem::Segment::detach()
 {
     if (!theMem)
         return;
 
     if (munmap(theMem, theSize)) {
-        debugs(54, 5, "SharedMemory::munmap: munmap: " << xstrerror());
-        fatal("SharedMemory::munmap failed");
+        debugs(54, 5, HERE << "munmap: " << xstrerror());
+        fatal("Ipc::Mem::Segment::detach failed to munmap");
     }
     theMem = 0;
 }
 
 /// Generate name for shared memory segment. Replaces all slashes with dots.
 String
-SharedMemory::GenerateName(const char *id)
+Ipc::Mem::Segment::GenerateName(const char *id)
 {
     String name("/squid-");
     for (const char *slash = strchr(id, '/'); slash; slash = strchr(id, '/')) {
similarity index 78%
rename from src/ipc/SharedMemory.h
rename to src/ipc/mem/Segment.h
index bba5d1e1ad560e21d012c5e9be09e4e79a759ef8..dc8475d60c61a65bd58bb3d35f52d43bbf15ed38 100644 (file)
@@ -3,17 +3,21 @@
  *
  */
 
-#ifndef SQUID_IPC_SHARED_MEMORY_H
-#define SQUID_IPC_SHARED_MEMORY_H
+#ifndef SQUID_IPC_MEM_SEGMENT_H
+#define SQUID_IPC_MEM_SEGMENT_H
 
 #include "SquidString.h"
 
+namespace Ipc {
+
+namespace Mem {
+
 /// POSIX shared memory segment
-class SharedMemory {
+class Segment {
 public:
     /// Create a shared memory segment.
-    SharedMemory(const char *const id);
-    ~SharedMemory();
+    Segment(const char *const id);
+    ~Segment();
 
     /// Create a new shared memory segment. Fails if a segment with
     /// the same name already exists.
@@ -36,4 +40,8 @@ private:
     void *theMem; ///< pointer to mmapped shared memory segment
 };
 
-#endif /* SQUID_IPC_SHARED_MEMORY_H */
+} // namespace Mem
+
+} // namespace Ipc
+
+#endif /* SQUID_IPC_MEM_SEGMENT_H */