fix: add thread safety for cave and river path mutexes

This commit is contained in:
2026-06-21 15:56:58 +08:00
parent 9a7fe1bfe9
commit 790f4a5aa4
8 changed files with 80 additions and 48 deletions

View File

@@ -17,11 +17,13 @@ public:
int cave_sum() const;
float& cave_probability();
std::shared_mutex& path_mutex();
private:
CaveHashMap m_paths;
unsigned m_seed = 0;
Random m_random;
float m_cave_probability = 0.035f;
std::shared_mutex m_path_mutex;
};
} // namespace Cubed

View File

@@ -12,6 +12,7 @@ class RiverWorm {
public:
RiverWorm();
~RiverWorm();
RiverHashMap& paths();
void init(unsigned world_seed);
void reload(unsigned world_seed);
@@ -21,12 +22,14 @@ public:
int river_sum() const;
float& river_probability();
std::shared_mutex& paths_mutex();
private:
RiverHashMap m_paths;
unsigned m_seed = 0;
Random m_random;
float m_probability = 0.01f;
std::shared_mutex m_paths_mutex;
};
}; // namespace Cubed

View File

@@ -104,6 +104,7 @@ private:
void submit_new_chunks();
void poll_finished_chunks();
void wait_all_chunk_tasks();
public:
World();

View File

@@ -48,7 +48,14 @@ public:
for (auto& w : m_workers) {
w.request_stop();
}
m_cv.notify_all();
for (auto& w : m_workers) {
if (w.joinable()) {
w.join();
}
}
}
template <typename F> auto enqueue(F&& f) {