Fixed an occasional crash resulting from multi-thread access of the image cache
This was a problem as of52db950e94
since the loading screen could access the image cache while the worker thread cleared it. (cherry-picked from commit6d0b7c8424
)
This commit is contained in:
parent
6b5ce73605
commit
504435023c
1 changed files with 9 additions and 1 deletions
|
@ -41,6 +41,7 @@
|
|||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/functional/hash_fwd.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
|
@ -105,23 +106,30 @@ class cache_type
|
|||
public:
|
||||
cache_type()
|
||||
: content_()
|
||||
, cache_lock_()
|
||||
{
|
||||
}
|
||||
|
||||
cache_item<T>& get_element(int index)
|
||||
{
|
||||
if(static_cast<unsigned>(index) >= content_.size())
|
||||
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_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Reference in a new issue