]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implement Ipc::Mem::Level().
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Mon, 18 Apr 2011 10:37:52 +0000 (14:37 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Mon, 18 Apr 2011 10:37:52 +0000 (14:37 +0400)
src/ipc/AtomicWord.h
src/ipc/mem/PagePool.h
src/ipc/mem/PageStack.h
src/ipc/mem/Pages.cc

index 5d30b7d27d0b1cc6fdc5bf5e324a905f7be4a5b4..9d9080f50212a57643c73e8df68e8b8fe63c2517 100644 (file)
@@ -27,7 +27,8 @@ public:
     bool operator ==(int v2) { return __sync_bool_compare_and_swap(&value, v2, value); }
 
     // TODO: no need for __sync_fetch_and_add here?
-    operator Value () const { return __sync_fetch_and_add(const_cast<Value*>(&value), 0); }
+    Value get() const { return __sync_fetch_and_add(const_cast<Value*>(&value), 0); }
+    operator Value () const { return get(); }
 
 private:
     Value value;
index 9c8d93a297ea865daf3076a13f24a1b31e8b551d..d151263f199a48c1e57a3a0e00292220a143fd88 100644 (file)
@@ -26,6 +26,8 @@ public:
     PagePool(const String &id);
 
     unsigned int capacity() const { return shared->theCapacity; }
+    /// lower bound for the number of free pages
+    unsigned int size() const { return pageIndex.size(); }
     size_t pageSize() const { return shared->thePageSize; }
 
     /// sets page ID and returns true unless no free pages are found
index 3048ba20a35f405d816f370d8ec31391c199cb2a..936a207cb4a52b2d497b71b019a5d6c4e89345a5 100644 (file)
@@ -25,6 +25,9 @@ public:
     /// attaches to the identified shared stack
     PageStack(const String &id);
 
+    /// lower bound for the number of free pages
+    unsigned int size() const { return max(0, shared->theSize.get()); }
+
     /// sets value and returns true unless no free page numbers are found
     bool pop(Value &value);
     /// makes value available as a free page number to future pop() callers
index 53f082a4a055d69ba18015f1fed03927afeb40c0..259720d4007d18afee9ebc57bf8f259a25c401ad 100644 (file)
@@ -72,8 +72,12 @@ Ipc::Mem::Limit()
     return Config.memMaxSize;
 }
 
-// TODO: Implement size_t Ipc::Mem::Level()
-
+size_t
+Ipc::Mem::Level()
+{
+    return ThePagePool ?
+        (ThePagePool->capacity() - ThePagePool->size()) * PageSize() : 0;
+}
 
 /// initializes shared memory pages
 class SharedMemPagesRr: public RegisteredRunner