Restore recursive locking for mutexes converted from CRITICAL_SECTION

CRITICAL_SECTION is reentrant; std::mutex is not. This caused deadlocks during world generation, post-processing, and saving.
This commit is contained in:
MatthewBeshay
2026-03-30 22:14:14 +11:00
parent 57e4bdd973
commit e4520df31f
19 changed files with 104 additions and 104 deletions

View File

@@ -144,7 +144,7 @@ LevelChunk* ServerChunkCache::create(
LevelChunk* lastChunk = chunk;
if ((chunk == nullptr) || (chunk->x != x) || (chunk->z != z)) {
{ std::lock_guard<std::mutex> lock(m_csLoadCreate);
{ std::lock_guard<std::recursive_mutex> lock(m_csLoadCreate);
chunk = load(x, z);
if (chunk == nullptr) {
if (source == nullptr) {
@@ -169,7 +169,7 @@ LevelChunk* ServerChunkCache::create(
#endif
{
// Successfully updated the cache
std::lock_guard<std::mutex> lock(m_csLoadCreate);
std::lock_guard<std::recursive_mutex> lock(m_csLoadCreate);
// 4J - added - this will run a recalcHeightmap if source is a
// randomlevelsource, which has been split out from source::getChunk
// so that we are doing it after the chunk has been added to the
@@ -649,7 +649,7 @@ bool ServerChunkCache::saveAllEntities() {
PIXBeginNamedEvent(0, "Save all entities");
PIXBeginNamedEvent(0, "saving to NBT");
{ std::lock_guard<std::mutex> lock(m_csLoadCreate);
{ std::lock_guard<std::recursive_mutex> lock(m_csLoadCreate);
for (auto it = m_loadedChunkList.begin(); it != m_loadedChunkList.end();
++it) {
storage->saveEntities(level, *it);
@@ -666,7 +666,7 @@ bool ServerChunkCache::saveAllEntities() {
}
bool ServerChunkCache::save(bool force, ProgressListener* progressListener) {
std::lock_guard<std::mutex> lock(m_csLoadCreate);
std::lock_guard<std::recursive_mutex> lock(m_csLoadCreate);
int saves = 0;
// 4J - added this to support progressListner