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;
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
/// 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
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