Skip to content

Commit

Permalink
Revert "Fixed an occasional crash resulting from multi-thread access …
Browse files Browse the repository at this point in the history
…of the image cache"

This reverts commit 6d0b7c8. Turns out there's
a better way to fix this problem without using mutexes, which have a noticeable
performance hit (5.2% of the execution time of game_display::draw_invalidated()
according to @jyrkive).

(cherry-picked from commit b8ad791)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent a5b8053 commit 1ec6904
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/image.cpp
Expand Up @@ -41,7 +41,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/functional/hash_fwd.hpp>

#include <mutex>
#include <set>

static lg::log_domain log_display("display");
Expand Down Expand Up @@ -106,30 +105,23 @@ 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()) {
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>
Expand Down

0 comments on commit 1ec6904

Please sign in to comment.