Skip to content

Commit

Permalink
use Mutex even for const methods
Browse files Browse the repository at this point in the history
const does not mean const here?
but it seems to be necessary to stay thread save
  • Loading branch information
EtlamGit committed Aug 5, 2019
1 parent 15bbb1c commit 48cd13f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chunkcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ QString ChunkCache::getPath() {

Chunk *ChunkCache::fetch(int x, int z) {
ChunkID id(x, z);
//mutex.lock();
mutex.lock();
Chunk *chunk = cache[id]; // const operation
//mutex.unlock();
mutex.unlock();
if (chunk != NULL) {
if (chunk->loaded)
return chunk;
Expand Down
4 changes: 2 additions & 2 deletions chunkloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void ChunkLoader::run() {
}
// get existing Chunk entry from Cache
ChunkID id(x, z);
//mutex->lock();
mutex->lock();
Chunk *chunk = cache[id]; // const operation
//mutex->unlock();
mutex->unlock();
// parse Chunk data
// Chunk will be flagged "loaded" in a thread save way
if (chunk) {
Expand Down

0 comments on commit 48cd13f

Please sign in to comment.