Vultraz

Untitled

May 28th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 0.99 KB | None | 0 0
  1.  src/image.cpp | 10 +++++++++-
  2.  1 file changed, 9 insertions(+), 1 deletion(-)
  3.  
  4. diff --git a/src/image.cpp b/src/image.cpp
  5. index fef85af7e4..67c0c32568 100644
  6. --- a/src/image.cpp
  7. +++ b/src/image.cpp
  8. @@ -41,6 +41,7 @@
  9.  #include <boost/algorithm/string.hpp>
  10.  #include <boost/functional/hash_fwd.hpp>
  11.  
  12. +#include <mutex>
  13.  #include <set>
  14.  
  15.  static lg::log_domain log_display("display");
  16. @@ -105,23 +106,30 @@ class cache_type
  17.  public:
  18.     cache_type()
  19.         : content_()
  20. +       , cache_lock_()
  21.     {
  22.     }
  23.  
  24.     cache_item<T>& get_element(int index)
  25.     {
  26. -       if(static_cast<unsigned>(index) >= content_.size())
  27. +       std::lock_guard<std::mutex> lock(cache_lock_);
  28. +
  29. +       if(static_cast<unsigned>(index) >= content_.size()) {
  30.             content_.resize(index + 1);
  31. +       }
  32. +
  33.         return content_[index];
  34.     }
  35.  
  36.     void flush()
  37.     {
  38. +       std::lock_guard<std::mutex> lock(cache_lock_);
  39.         content_.clear();
  40.     }
  41.  
  42.  private:
  43.     std::vector<cache_item<T>> content_;
  44. +   std::mutex cache_lock_;
  45.  };
  46.  
  47.  template<typename T>
Advertisement
Add Comment
Please, Sign In to add comment