]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/mem/PagePool.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / mem / PagePool.h
index f2b0ef827b0ef4f8ecf6e80672f54e3affacc324..bb0f758a381b49367e82dcf2e2cc3aeb4bb8c2c2 100644 (file)
@@ -1,22 +1,29 @@
 /*
- * $Id$
+ * Copyright (C) 1996-2017 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_POOL_H
 #define SQUID_IPC_MEM_PAGE_POOL_H
 
+#include "ipc/mem/Page.h"
 #include "ipc/mem/PageStack.h"
 #include "ipc/mem/Pointer.h"
 
-namespace Ipc {
+namespace Ipc
+{
 
-namespace Mem {
+namespace Mem
+{
 
 /// Atomic container of shared memory pages. Implemented using a collection of
 /// Segments, each with a PageStack index of free pages. All pools must be
 /// created by a single process.
-class PagePool {
+class PagePool
+{
 public:
     typedef Ipc::Mem::Owner<PageStack> Owner;
 
@@ -28,17 +35,24 @@ public:
     size_t pageSize() const { return pageIndex->pageSize(); }
     /// lower bound for the number of free pages
     unsigned int size() const { return pageIndex->size(); }
+    /// approximate number of shared memory pages used now
+    size_t level() const { return capacity() - size(); }
+    /// approximate number of shared memory pages used now for given purpose
+    size_t level(const int purpose) const;
 
     /// sets page ID and returns true unless no free pages are found
-    bool get(PageId &page) { return pageIndex->pop(page); }
+    bool get(const PageId::Purpose purpose, PageId &page);
     /// makes identified page available as a free page to future get() callers
-    void put(PageId &page) { return pageIndex->push(page); }
+    void put(PageId &page);
     /// converts page handler into a temporary writeable shared memory pointer
     char *pagePointer(const PageId &page);
 
 private:
     Ipc::Mem::Pointer<PageStack> pageIndex; ///< free pages index
-    char *theBuf; ///< pages storage
+    typedef std::atomic<size_t> Levels_t;
+    /// number of shared memory pages used now for each purpose
+    Levels_t * const theLevels;
+    char *const theBuf; ///< pages storage
 };
 
 } // namespace Mem
@@ -46,3 +60,4 @@ private:
 } // namespace Ipc
 
 #endif // SQUID_IPC_MEM_PAGE_POOL_H
+