LCOV - code coverage report
Current view: top level - src/leveldb/db - snapshot.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 6 23 26.1 %
Date: 2015-10-12 22:39:14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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         976 : 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         488 : class SnapshotList {
      31             :  public:
      32         244 :   SnapshotList() {
      33         244 :     list_.prev_ = &list_;
      34         244 :     list_.next_ = &list_;
      35           0 :   }
      36             : 
      37           7 :   bool empty() const { return list_.next_ == &list_; }
      38           0 :   SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
      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);
      54           0 :     s->prev_->next_ = s->next_;
      55           0 :     s->next_->prev_ = s->prev_;
      56           0 :     delete s;
      57           0 :   }
      58             : 
      59             :  private:
      60             :   // Dummy head of doubly-linked list of snapshots
      61             :   SnapshotImpl list_;
      62             : };
      63             : 
      64             : }  // namespace leveldb
      65             : 
      66             : #endif  // STORAGE_LEVELDB_DB_SNAPSHOT_H_

Generated by: LCOV version 1.11