]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/mem/Page.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ipc / mem / Page.h
index b8edf95b9e0e3868f42852f5e6fea3f5b054a988..575537a0a53d9fef2757cdc9925d625864a1d9e9 100644 (file)
@@ -1,29 +1,48 @@
 /*
- * $Id$
+ * Copyright (C) 1996-2020 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.
  */
 
 #ifndef SQUID_IPC_MEM_PAGE_H
 #define SQUID_IPC_MEM_PAGE_H
 
-#if HAVE_IOSFWD
+#include "ipc/mem/forward.h"
+
 #include <iosfwd>
-#endif
 
-namespace Ipc {
+namespace Ipc
+{
 
-namespace Mem {
+namespace Mem
+{
 
 /// Shared memory page identifier, address, or handler
-class PageId {
+class PageId
+{
 public:
-    PageId(): pool(0), number(0) {}
+    PageId(): pool(0), number(0), purpose(maxPurpose) {}
+
+    /// true if and only if both critical components have been initialized
+    bool set() const { return pool && number; }
+
+    // safer than bool which would enable silent casts to int
+    typedef const uint32_t PageId::*SaferBool;
+    operator SaferBool() const { return set() ? &PageId::number : NULL; }
 
-    operator bool() const { return pool && number; }
+    /// The ID of a PagePool (and/or PageStack) this page belongs to.
+    /// Positive values are (ab)used to detect in-use pages. See set().
+    /// Eventually, they may identify a PageStack in a multi-segment PagePool.
+    /// These IDs also distinguish page pools/stacks in debugging logs.
+    PoolId pool;
 
-    uint32_t pool; ///< page pool ID within Squid
     // uint32_t segment; ///< memory segment ID within the pool; unused for now
     uint32_t number; ///< page number within the segment
+
+    enum Purpose { cachePage, ioPage, maxPurpose };
+    Purpose purpose; ///< page purpose
 };
 
 /// writes page address (e.g., "sh_page5.3"), for debugging
@@ -34,3 +53,4 @@ std::ostream &operator <<(std::ostream &os, const PageId &page);
 } // namespace Ipc
 
 #endif // SQUID_IPC_MEM_PAGE_H
+