hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
single_pointer_cache.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SINGLE_POINTER_CACHE_HPP
7 #define IROHA_SINGLE_POINTER_CACHE_HPP
8 
9 #include <memory>
10 #include <mutex>
11 
12 namespace iroha {
13  namespace cache {
14 
19  template <typename DataType>
21  public:
25  using DataPointer = std::shared_ptr<std::decay_t<DataType>>;
26 
31  void insert(DataPointer data);
32 
37  DataPointer get() const;
38 
42  void release();
43 
44  private:
45  DataPointer stored_data_;
46 
47  mutable std::mutex mutex_;
48  };
49 
50  template <typename DataType>
53  std::lock_guard<std::mutex> lock(mutex_);
54 
55  stored_data_ = std::move(data);
56  }
57 
58  template <typename DataType>
61  std::lock_guard<std::mutex> lock(mutex_);
62 
63  return stored_data_;
64  }
65 
66  template <typename DataType>
68  std::lock_guard<std::mutex> lock(mutex_);
69 
70  stored_data_.reset();
71  }
72 
73  } // namespace cache
74 } // namespace iroha
75 
76 #endif // IROHA_SINGLE_POINTER_CACHE_HPP
void insert(DataPointer data)
Definition: single_pointer_cache.hpp:51
Definition: single_pointer_cache.hpp:20
std::shared_ptr< std::decay_t< DataType >> DataPointer
Definition: single_pointer_cache.hpp:25
Definition: block_query.hpp:16
void release()
Definition: single_pointer_cache.hpp:67
DataPointer get() const
Definition: single_pointer_cache.hpp:60