CatapultServer  v0.5.0.1 (Elephant)
CacheHeight.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/types.h"
24 
25 namespace catapult { namespace cache {
26 
29  public:
32  : m_height(height)
33  , m_readLock(std::move(readLock))
34  {}
35 
36  public:
38  Height get() const {
39  return m_height;
40  }
41 
42  private:
45  };
46 
49  public:
52  : m_height(height)
53  , m_readLock(std::move(readLock))
54  , m_writeLock(m_readLock.promoteToWriter())
55  {}
56 
57  public:
59  void set(Height height) {
60  m_height = height;
61  }
62 
63  private:
67  };
68 
70  class CacheHeight {
71  public:
74  auto readLock = m_lock.acquireReader();
75  return CacheHeightView(m_height, std::move(readLock));
76  }
77 
80  auto readLock = m_lock.acquireReader();
81  return CacheHeightModifier(m_height, std::move(readLock));
82  }
83 
84  private:
87  };
88 }}
catapult::cache::CacheHeightModifier::m_writeLock
utils::SpinReaderWriterLock::WriterLockGuard m_writeLock
Definition: CacheHeight.h:66
catapult::cache::CacheHeightModifier::CacheHeightModifier
CacheHeightModifier(Height &height, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a write only view around height with lock context readLock.
Definition: CacheHeight.h:51
catapult::cache::CacheHeightModifier
A write only view on top of a cache height.
Definition: CacheHeight.h:48
catapult::cache::CacheHeightView::m_height
Height m_height
Definition: CacheHeight.h:43
catapult::cache::CacheHeightView::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: CacheHeight.h:44
catapult::cache::CacheHeight::m_height
Height m_height
Definition: CacheHeight.h:85
SpinReaderWriterLock.h
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::utils::BasicSpinReaderWriterLock::WriterLockGuard
A writer lock guard.
Definition: SpinReaderWriterLock.h:83
catapult::cache::CacheHeightModifier::m_height
Height & m_height
Definition: CacheHeight.h:64
catapult::cache::CacheHeightModifier::set
void set(Height height)
Sets the cache height to height.
Definition: CacheHeight.h:59
catapult::cache::CacheHeightView::CacheHeightView
CacheHeightView(Height height, utils::SpinReaderWriterLock::ReaderLockGuard &&readLock)
Creates a cache height view around height with lock context readLock.
Definition: CacheHeight.h:31
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard
A reader lock guard.
Definition: SpinReaderWriterLock.h:99
catapult::cache::CacheHeight::modifier
CacheHeightModifier modifier()
Gets a write only view of the height.
Definition: CacheHeight.h:79
types.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::CacheHeightView::get
Height get() const
Returns the height.
Definition: CacheHeight.h:38
catapult::cache::CacheHeightView
A read only view on top of a cache height.
Definition: CacheHeight.h:28
catapult::cache::CacheHeight
A synchronized height associated with a catapult cache.
Definition: CacheHeight.h:70
catapult::cache::CacheHeight::m_lock
utils::SpinReaderWriterLock m_lock
Definition: CacheHeight.h:86
catapult::cache::CacheHeightModifier::m_readLock
utils::SpinReaderWriterLock::ReaderLockGuard m_readLock
Definition: CacheHeight.h:65
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36
catapult::cache::CacheHeight::view
CacheHeightView view() const
Gets a read only view of the height.
Definition: CacheHeight.h:73