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 "db/dbformat.h"
9 #include "leveldb/db.h"
15 // Snapshots are kept in a doubly-linked list in the DB.
16 // Each SnapshotImpl corresponds to a particular sequence number.
17 class SnapshotImpl
: public Snapshot
{
19 SequenceNumber number_
; // const after creation
22 friend class SnapshotList
;
24 // SnapshotImpl is kept in a doubly-linked circular list
28 SnapshotList
* list_
; // just for sanity checks
38 bool empty() const { return list_
.next_
== &list_
; }
39 SnapshotImpl
* oldest() const { assert(!empty()); return list_
.next_
; }
40 SnapshotImpl
* newest() const { assert(!empty()); return list_
.prev_
; }
42 const SnapshotImpl
* New(SequenceNumber seq
) {
43 SnapshotImpl
* s
= new SnapshotImpl
;
47 s
->prev_
= list_
.prev_
;
53 void Delete(const SnapshotImpl
* s
) {
54 assert(s
->list_
== this);
55 s
->prev_
->next_
= s
->next_
;
56 s
->next_
->prev_
= s
->prev_
;
61 // Dummy head of doubly-linked list of snapshots
65 } // namespace leveldb
67 #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_