Advertisement
Vultraz

Untitled

May 28th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. template<typename T>
  2. class cache_type
  3. {
  4. public:
  5.     cache_type()
  6.         : content_()
  7.         , cache_lock_()
  8.     {
  9.     }
  10.  
  11.     cache_item<T>& get_element(int index)
  12.     {
  13.         std::lock_guard<std::mutex> lock(cache_lock_);
  14.  
  15.         if(static_cast<unsigned>(index) >= content_.size()) {
  16.             content_.resize(index + 1);
  17.         }
  18.  
  19.         return content_[index];
  20.     }
  21.  
  22.     void flush()
  23.     {
  24.         std::lock_guard<std::mutex> lock(cache_lock_);
  25.         content_.clear();
  26.     }
  27.  
  28. private:
  29.     std::vector<cache_item<T>> content_;
  30.     std::mutex cache_lock_;
  31. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement