summaryrefslogtreecommitdiff
path: root/db/memtable.h
diff options
context:
space:
mode:
authordgrogan@chromium.org <dgrogan@chromium.org@62dab493-f737-651d-591e-8d6aee1b9529>2011-05-21 02:17:43 +0000
committerdgrogan@chromium.org <dgrogan@chromium.org@62dab493-f737-651d-591e-8d6aee1b9529>2011-05-21 02:17:43 +0000
commitda7990950787257cb312ca562ce5977749afc3e9 (patch)
tree91fe98f6e14e74c794392b22105a47a58499edff /db/memtable.h
parent3c111335a760d8d82414b91a54f740df09dd4f8f (diff)
downloadleveldb-da7990950787257cb312ca562ce5977749afc3e9.tar.gz
sync with upstream @ 21409451
Check the NEWS file for details of what changed. git-svn-id: https://leveldb.googlecode.com/svn/trunk@28 62dab493-f737-651d-591e-8d6aee1b9529
Diffstat (limited to 'db/memtable.h')
-rw-r--r--db/memtable.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/db/memtable.h b/db/memtable.h
index 45b3342..2e9bd61 100644
--- a/db/memtable.h
+++ b/db/memtable.h
@@ -19,8 +19,21 @@ class MemTableIterator;
class MemTable {
public:
+ // MemTables are reference counted. The initial reference count
+ // is zero and the caller must call Ref() at least once.
explicit MemTable(const InternalKeyComparator& comparator);
- ~MemTable();
+
+ // Increase reference count.
+ void Ref() { ++refs_; }
+
+ // Drop reference count. Delete if no more references exist.
+ void Unref() {
+ --refs_;
+ assert(refs_ >= 0);
+ if (refs_ <= 0) {
+ delete this;
+ }
+ }
// Returns an estimate of the number of bytes of data in use by this
// data structure.
@@ -45,6 +58,8 @@ class MemTable {
const Slice& value);
private:
+ ~MemTable(); // Private since only Unref() should be used to delete it
+
struct KeyComparator {
const InternalKeyComparator comparator;
explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { }
@@ -56,6 +71,7 @@ class MemTable {
typedef SkipList<const char*, KeyComparator> Table;
KeyComparator comparator_;
+ int refs_;
Arena arena_;
Table table_;