]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Queue.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / ipc / Queue.cc
index 2d10fa884bb3d6aa3385c5fa11306a8d8e3f91c1..1fffc29908ff66b38cf022cc1f41ad35d4df7509 100644 (file)
@@ -1,8 +1,13 @@
 /*
- * DEBUG: section 54    Interprocess Communication
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 54    Interprocess Communication */
+
 #include "squid.h"
 #include "base/TextException.h"
 #include "Debug.h"
@@ -39,8 +44,8 @@ ReadersId(String id)
 
 InstanceIdDefinitions(Ipc::QueueReader, "ipcQR");
 
-Ipc::QueueReader::QueueReader(): popBlocked(1), popSignal(0),
-        rateLimit(0), balance(0)
+Ipc::QueueReader::QueueReader(): popBlocked(true), popSignal(false),
+    rateLimit(0), balance(0)
 {
     debugs(54, 7, HERE << "constructed " << id);
 }
@@ -48,7 +53,7 @@ Ipc::QueueReader::QueueReader(): popBlocked(1), popSignal(0),
 /* QueueReaders */
 
 Ipc::QueueReaders::QueueReaders(const int aCapacity): theCapacity(aCapacity),
-        theReaders(theCapacity)
+    theReaders(theCapacity)
 {
     Must(theCapacity > 0);
 }
@@ -68,8 +73,8 @@ Ipc::QueueReaders::SharedMemorySize(const int capacity)
 // OneToOneUniQueue
 
 Ipc::OneToOneUniQueue::OneToOneUniQueue(const unsigned int aMaxItemSize, const int aCapacity):
-        theIn(0), theOut(0), theSize(0), theMaxItemSize(aMaxItemSize),
-        theCapacity(aCapacity)
+    theIn(0), theOut(0), theSize(0), theMaxItemSize(aMaxItemSize),
+    theCapacity(aCapacity)
 {
     Must(theMaxItemSize > 0);
     Must(theCapacity > 0);
@@ -90,6 +95,25 @@ Ipc::OneToOneUniQueue::Items2Bytes(const unsigned int maxItemSize, const int siz
     return sizeof(OneToOneUniQueue) + maxItemSize * size;
 }
 
+/// start state reporting (by reporting queue parameters)
+/// The labels reflect whether the caller owns theIn or theOut data member and,
+/// hence, cannot report the other value reliably.
+void
+Ipc::OneToOneUniQueue::statOpen(std::ostream &os, const char *inLabel, const char *outLabel, const uint32_t count) const
+{
+    os << "{ size: " << count <<
+       ", capacity: " << theCapacity <<
+       ", " << inLabel << ": " << theIn <<
+       ", " << outLabel << ": " << theOut;
+}
+
+/// end state reporting started by statOpen()
+void
+Ipc::OneToOneUniQueue::statClose(std::ostream &os) const
+{
+    os << "}\n";
+}
+
 /* OneToOneUniQueues */
 
 Ipc::OneToOneUniQueues::OneToOneUniQueues(const int aCapacity, const unsigned int maxItemSize, const int queueCapacity): theCapacity(aCapacity)
@@ -126,13 +150,13 @@ Ipc::OneToOneUniQueues::operator [](const int index) const
 // BaseMultiQueue
 
 Ipc::BaseMultiQueue::BaseMultiQueue(const int aLocalProcessId):
-        theLocalProcessId(aLocalProcessId),
-        theLastPopProcessId(std::numeric_limits<int>::max() - 1)
+    theLocalProcessId(aLocalProcessId),
+    theLastPopProcessId(std::numeric_limits<int>::max() - 1)
 {
 }
 
 void
-Ipc::BaseMultiQueue::clearReaderSignal(const int remoteProcessId)
+Ipc::BaseMultiQueue::clearReaderSignal(const int /*remoteProcessId*/)
 {
     QueueReader &reader = localReader();
     debugs(54, 7, "reader: " << reader.id);
@@ -200,11 +224,11 @@ Ipc::FewToFewBiQueue::Init(const String &id, const int groupASize, const int gro
 }
 
 Ipc::FewToFewBiQueue::FewToFewBiQueue(const String &id, const Group aLocalGroup, const int aLocalProcessId):
-        BaseMultiQueue(aLocalProcessId),
-        metadata(shm_old(Metadata)(MetadataId(id).termedBuf())),
-        queues(shm_old(OneToOneUniQueues)(QueuesId(id).termedBuf())),
-        readers(shm_old(QueueReaders)(ReadersId(id).termedBuf())),
-        theLocalGroup(aLocalGroup)
+    BaseMultiQueue(aLocalProcessId),
+    metadata(shm_old(Metadata)(MetadataId(id).termedBuf())),
+    queues(shm_old(OneToOneUniQueues)(QueuesId(id).termedBuf())),
+    readers(shm_old(QueueReaders)(ReadersId(id).termedBuf())),
+    theLocalGroup(aLocalGroup)
 {
     Must(queues->theCapacity == metadata->theGroupASize * metadata->theGroupBSize * 2);
     Must(readers->theCapacity == metadata->theGroupASize + metadata->theGroupBSize);
@@ -310,17 +334,17 @@ Ipc::FewToFewBiQueue::remotesIdOffset() const
 }
 
 Ipc::FewToFewBiQueue::Metadata::Metadata(const int aGroupASize, const int aGroupAIdOffset, const int aGroupBSize, const int aGroupBIdOffset):
-        theGroupASize(aGroupASize), theGroupAIdOffset(aGroupAIdOffset),
-        theGroupBSize(aGroupBSize), theGroupBIdOffset(aGroupBIdOffset)
+    theGroupASize(aGroupASize), theGroupAIdOffset(aGroupAIdOffset),
+    theGroupBSize(aGroupBSize), theGroupBIdOffset(aGroupBIdOffset)
 {
     Must(theGroupASize > 0);
     Must(theGroupBSize > 0);
 }
 
 Ipc::FewToFewBiQueue::Owner::Owner(const String &id, const int groupASize, const int groupAIdOffset, const int groupBSize, const int groupBIdOffset, const unsigned int maxItemSize, const int capacity):
-        metadataOwner(shm_new(Metadata)(MetadataId(id).termedBuf(), groupASize, groupAIdOffset, groupBSize, groupBIdOffset)),
-        queuesOwner(shm_new(OneToOneUniQueues)(QueuesId(id).termedBuf(), groupASize*groupBSize*2, maxItemSize, capacity)),
-        readersOwner(shm_new(QueueReaders)(ReadersId(id).termedBuf(), groupASize+groupBSize))
+    metadataOwner(shm_new(Metadata)(MetadataId(id).termedBuf(), groupASize, groupAIdOffset, groupBSize, groupBIdOffset)),
+    queuesOwner(shm_new(OneToOneUniQueues)(QueuesId(id).termedBuf(), groupASize*groupBSize*2, maxItemSize, capacity)),
+    readersOwner(shm_new(QueueReaders)(ReadersId(id).termedBuf(), groupASize+groupBSize))
 {
 }
 
@@ -340,10 +364,10 @@ Ipc::MultiQueue::Init(const String &id, const int processCount, const int proces
 }
 
 Ipc::MultiQueue::MultiQueue(const String &id, const int localProcessId):
-        BaseMultiQueue(localProcessId),
-        metadata(shm_old(Metadata)(MetadataId(id).termedBuf())),
-        queues(shm_old(OneToOneUniQueues)(QueuesId(id).termedBuf())),
-        readers(shm_old(QueueReaders)(ReadersId(id).termedBuf()))
+    BaseMultiQueue(localProcessId),
+    metadata(shm_old(Metadata)(MetadataId(id).termedBuf())),
+    queues(shm_old(OneToOneUniQueues)(QueuesId(id).termedBuf())),
+    readers(shm_old(QueueReaders)(ReadersId(id).termedBuf()))
 {
     Must(queues->theCapacity == metadata->theProcessCount * metadata->theProcessCount);
     Must(readers->theCapacity == metadata->theProcessCount);
@@ -414,15 +438,15 @@ Ipc::MultiQueue::remotesIdOffset() const
 }
 
 Ipc::MultiQueue::Metadata::Metadata(const int aProcessCount, const int aProcessIdOffset):
-        theProcessCount(aProcessCount), theProcessIdOffset(aProcessIdOffset)
+    theProcessCount(aProcessCount), theProcessIdOffset(aProcessIdOffset)
 {
     Must(theProcessCount > 0);
 }
 
 Ipc::MultiQueue::Owner::Owner(const String &id, const int processCount, const int processIdOffset, const unsigned int maxItemSize, const int capacity):
-        metadataOwner(shm_new(Metadata)(MetadataId(id).termedBuf(), processCount, processIdOffset)),
-        queuesOwner(shm_new(OneToOneUniQueues)(QueuesId(id).termedBuf(), processCount*processCount, maxItemSize, capacity)),
-        readersOwner(shm_new(QueueReaders)(ReadersId(id).termedBuf(), processCount))
+    metadataOwner(shm_new(Metadata)(MetadataId(id).termedBuf(), processCount, processIdOffset)),
+    queuesOwner(shm_new(OneToOneUniQueues)(QueuesId(id).termedBuf(), processCount*processCount, maxItemSize, capacity)),
+    readersOwner(shm_new(QueueReaders)(ReadersId(id).termedBuf(), processCount))
 {
 }
 
@@ -432,3 +456,4 @@ Ipc::MultiQueue::Owner::~Owner()
     delete queuesOwner;
     delete readersOwner;
 }
+