mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
src/util/numeric.{cpp,h}: Fix FacePositionCache data race
This commit is contained in:
@@ -23,13 +23,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "log.h"
|
||||
#include "../constants.h" // BS, MAP_BLOCKSIZE
|
||||
#include "../noise.h" // PseudoRandom, PcgRandom
|
||||
#include "../jthread/jmutexautolock.h"
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
std::map<u16, std::vector<v3s16> > FacePositionCache::m_cache;
|
||||
JMutex FacePositionCache::m_cache_mutex;
|
||||
// Calculate the borders of a "d-radius" cube
|
||||
// TODO: Make it work without mutex and data races, probably thread-local
|
||||
std::vector<v3s16> FacePositionCache::getFacePositions(u16 d)
|
||||
{
|
||||
JMutexAutoLock cachelock(m_cache_mutex);
|
||||
if (m_cache.find(d) != m_cache.end())
|
||||
return m_cache[d];
|
||||
|
||||
|
Reference in New Issue
Block a user