25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

66 satır
1.6 KiB

  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. #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
  5. #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
  6. #include "leveldb/db.h"
  7. namespace leveldb {
  8. class SnapshotList;
  9. // Snapshots are kept in a doubly-linked list in the DB.
  10. // Each SnapshotImpl corresponds to a particular sequence number.
  11. class SnapshotImpl : public Snapshot {
  12. public:
  13. SequenceNumber number_; // const after creation
  14. private:
  15. friend class SnapshotList;
  16. // SnapshotImpl is kept in a doubly-linked circular list
  17. SnapshotImpl* prev_;
  18. SnapshotImpl* next_;
  19. SnapshotList* list_; // just for sanity checks
  20. };
  21. class SnapshotList {
  22. public:
  23. SnapshotList() {
  24. list_.prev_ = &list_;
  25. list_.next_ = &list_;
  26. }
  27. bool empty() const { return list_.next_ == &list_; }
  28. SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
  29. SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
  30. const SnapshotImpl* New(SequenceNumber seq) {
  31. SnapshotImpl* s = new SnapshotImpl;
  32. s->number_ = seq;
  33. s->list_ = this;
  34. s->next_ = &list_;
  35. s->prev_ = list_.prev_;
  36. s->prev_->next_ = s;
  37. s->next_->prev_ = s;
  38. return s;
  39. }
  40. void Delete(const SnapshotImpl* s) {
  41. assert(s->list_ == this);
  42. s->prev_->next_ = s->next_;
  43. s->next_->prev_ = s->prev_;
  44. delete s;
  45. }
  46. private:
  47. // Dummy head of doubly-linked list of snapshots
  48. SnapshotImpl list_;
  49. };
  50. }
  51. #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_