1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
5 #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
6 #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
8 #include "leveldb/db.h"
14 // Snapshots are kept in a doubly-linked list in the DB.
15 // Each SnapshotImpl corresponds to a particular sequence number.
16 class SnapshotImpl : public Snapshot {
18 SequenceNumber number_; // const after creation
21 friend class SnapshotList;
23 // SnapshotImpl is kept in a doubly-linked circular list
27 SnapshotList* list_; // just for sanity checks
37 bool empty() const { return list_.next_ == &list_; }
38 SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
39 SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
41 const SnapshotImpl* New(SequenceNumber seq) {
42 SnapshotImpl* s = new SnapshotImpl;
46 s->prev_ = list_.prev_;
52 void Delete(const SnapshotImpl* s) {
53 assert(s->list_ == this);
54 s->prev_->next_ = s->next_;
55 s->next_->prev_ = s->prev_;
60 // Dummy head of doubly-linked list of snapshots
64 } // namespace leveldb
66 #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_