CatapultServer  v0.5.0.1 (Elephant)
LocalNodeChainScore.h
Go to the documentation of this file.
1 
21 #pragma once
24 
25 namespace catapult { namespace extensions {
26 
30  public:
32  LocalNodeChainScore() = default;
33 
35  explicit LocalNodeChainScore(const model::ChainScore& score) : m_score (score)
36  {}
37 
38  public:
41  auto readLock = m_lock.acquireReader();
42  return m_score;
43  }
44 
46  void set(const model::ChainScore& chainScore) {
47  auto readLock = m_lock.acquireReader();
48  auto writeLock = readLock.promoteToWriter();
49  m_score = chainScore;
50  }
51 
52  public:
55  auto readLock = m_lock.acquireReader();
56  auto writeLock = readLock.promoteToWriter();
57  m_score += rhs;
58  return *this;
59  }
60 
61  private:
64  };
65 }}
catapult::extensions::LocalNodeChainScore::m_score
model::ChainScore m_score
Definition: LocalNodeChainScore.h:62
catapult::utils::BasicSpinReaderWriterLock::ReaderLockGuard::promoteToWriter
WriterLockGuard promoteToWriter()
Definition: SpinReaderWriterLock.h:117
catapult::extensions::LocalNodeChainScore::operator+=
LocalNodeChainScore & operator+=(const model::ChainScore &rhs)
Adds rhs to this chain score.
Definition: LocalNodeChainScore.h:54
catapult::extensions::LocalNodeChainScore::m_lock
utils::SpinReaderWriterLock m_lock
Definition: LocalNodeChainScore.h:63
SpinReaderWriterLock.h
catapult::model::ChainScore
Definition: ChainScore.h:30
catapult::utils::BasicSpinReaderWriterLock::acquireReader
ReaderLockGuard acquireReader()
Blocks until a reader lock can be acquired.
Definition: SpinReaderWriterLock.h:153
catapult::extensions::LocalNodeChainScore::LocalNodeChainScore
LocalNodeChainScore()=default
Creates a default local node chain score.
catapult::extensions::LocalNodeChainScore::LocalNodeChainScore
LocalNodeChainScore(const model::ChainScore &score)
Creates a local node chain score around score.
Definition: LocalNodeChainScore.h:35
catapult::extensions::LocalNodeChainScore::get
model::ChainScore get() const
Gets the current chain score.
Definition: LocalNodeChainScore.h:40
ChainScore.h
catapult::extensions::LocalNodeChainScore
Definition: LocalNodeChainScore.h:29
catapult::extensions::LocalNodeChainScore::set
void set(const model::ChainScore &chainScore)
Sets the current chain score to chainScore.
Definition: LocalNodeChainScore.h:46
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::BasicSpinReaderWriterLock
Definition: SpinReaderWriterLock.h:36