db/snapshot.h

filter: Statementstmt 19.0% 4 / 21 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 14.8% 4 / 27 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« util/mutexlock.h ↑ Summary util/logging.cc »
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.
4  
5 #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
6 #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
7  
8 #include "leveldb/db.h"
9  
10 namespace leveldb {
11  
12 class SnapshotList;
13  
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 {
17 public:
18 SequenceNumber number_; // const after creation
19  
20 private:
21 friend class SnapshotList;
22  
23 // SnapshotImpl is kept in a doubly-linked circular list
24 SnapshotImpl* prev_;
25 SnapshotImpl* next_;
26  
27 SnapshotList* list_; // just for sanity checks
28 };
29  
30 class SnapshotList {
31 public:
32 4 SnapshotList() {
33 4 list_.prev_ = &list_;
34 4 list_.next_ = &list_;
35 4 }
36  
37 0 bool empty() const { return list_.next_ == &list_; }
38 0 ▶ SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
Branch: 1 branch
BranchTrueFalseTotal
SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 0 0 0
39 SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
40  
41 0 const SnapshotImpl* New(SequenceNumber seq) {
42 0 SnapshotImpl* s = new SnapshotImpl;
43 0 s->number_ = seq;
44 0 s->list_ = this;
45 0 s->next_ = &list_;
46 0 s->prev_ = list_.prev_;
47 0 s->prev_->next_ = s;
48 0 s->next_->prev_ = s;
49 0 return s;
50 }
51  
52 0 void Delete(const SnapshotImpl* s) {
53 0 ▶ assert(s->list_ == this);
Branch: 1 branch
BranchTrueFalseTotal
assert(s->list_ == this); 0 0 0
54 0 s->prev_->next_ = s->next_;
55 0 s->next_->prev_ = s->prev_;
56 0 ▶ delete s;
Branch: 1 branch
BranchTrueFalseTotal
delete s; 0 0 0
57 0 }
58  
59 private:
60 // Dummy head of doubly-linked list of snapshots
61 SnapshotImpl list_;
62 };
63  
64 }
65  
66 #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
« util/mutexlock.h ↑ Summary util/logging.cc »