Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class cache_type
- {
- public:
- cache_type()
- : content_()
- , cache_lock_()
- {
- }
- cache_item<T>& get_element(int index)
- {
- std::lock_guard<std::mutex> lock(cache_lock_);
- if(static_cast<unsigned>(index) >= content_.size()) {
- content_.resize(index + 1);
- }
- return content_[index];
- }
- void flush()
- {
- std::lock_guard<std::mutex> lock(cache_lock_);
- content_.clear();
- }
- private:
- std::vector<cache_item<T>> content_;
- std::mutex cache_lock_;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement