Skip to content

Commit

Permalink
Trailing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Aug 28, 2024
1 parent ea481c3 commit 0d0132b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
3 changes: 1 addition & 2 deletions core/debugger/remote_debugger_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ void RemoteDebuggerPeerTCP::_read_in() {
Error err = decode_variant(var, buf, in_pos, &read);
ERR_CONTINUE(read != in_pos || err != OK);
ERR_CONTINUE_MSG(var.get_type() != Variant::ARRAY, "Malformed packet received, not an Array.");
mutex.lock();
MutexLock lock(mutex);
in_queue.push_back(var);
mutex.unlock();
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,13 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
return;
}

ResourceCache::lock.lock();
MutexLock lock(ResourceCache::lock);

if (p_remapped) {
ResourceLoader::remapped_list.add(&remapped_list);
} else {
ResourceLoader::remapped_list.remove(&remapped_list);
}

ResourceCache::lock.unlock();
}

#ifdef TOOLS_ENABLED
Expand Down Expand Up @@ -564,14 +562,13 @@ Resource::~Resource() {
return;
}

ResourceCache::lock.lock();
MutexLock lock(ResourceCache::lock);
// Only unregister from the cache if this is the actual resource listed there.
// (Other resources can have the same value in `path_cache` if loaded with `CACHE_IGNORE`.)
HashMap<String, Resource *>::Iterator E = ResourceCache::resources.find(path_cache);
if (likely(E && E->value == this)) {
ResourceCache::resources.remove(E);
}
ResourceCache::lock.unlock();
}

HashMap<String, Resource *> ResourceCache::resources;
Expand Down
3 changes: 1 addition & 2 deletions core/object/worker_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,8 @@ void WorkerThreadPool::wait_for_group_task_completion(GroupID p_group) {
}
}

task_mutex.lock(); // This mutex is needed when Physics 2D and/or 3D is selected to run on a separate thread.
MutexLock task_lock(task_mutex); // This mutex is needed when Physics 2D and/or 3D is selected to run on a separate thread.
groups.erase(p_group);
task_mutex.unlock();
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ void EditorFileSystem::_update_script_documentation() {
return;
}

update_script_mutex.lock();
MutexLock update_script_lock(update_script_mutex);

EditorProgress *ep = nullptr;
if (update_script_paths_documentation.size() > 1) {
Expand Down Expand Up @@ -1934,7 +1934,6 @@ void EditorFileSystem::_update_script_documentation() {
memdelete_notnull(ep);

update_script_paths_documentation.clear();
update_script_mutex.unlock();
}

void EditorFileSystem::_process_update_pending() {
Expand Down
10 changes: 3 additions & 7 deletions modules/navigation/2d/nav_mesh_generator_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void NavMeshGenerator2D::sync() {
return;
}

baking_navmesh_mutex.lock();
generator_task_mutex.lock();
MutexLock baking_navmesh_lock(baking_navmesh_mutex);
MutexLock generator_task_lock(generator_task_mutex);

LocalVector<WorkerThreadPool::TaskID> finished_task_ids;

Expand All @@ -111,9 +111,6 @@ void NavMeshGenerator2D::sync() {
for (WorkerThreadPool::TaskID finished_task_id : finished_task_ids) {
generator_tasks.erase(finished_task_id);
}

generator_task_mutex.unlock();
baking_navmesh_mutex.unlock();
}

void NavMeshGenerator2D::cleanup() {
Expand Down Expand Up @@ -209,15 +206,14 @@ void NavMeshGenerator2D::bake_from_source_geometry_data_async(Ref<NavigationPoly
baking_navmeshes.insert(p_navigation_mesh);
baking_navmesh_mutex.unlock();

generator_task_mutex.lock();
MutexLock generator_task_lock(generator_task_mutex);
NavMeshGeneratorTask2D *generator_task = memnew(NavMeshGeneratorTask2D);
generator_task->navigation_mesh = p_navigation_mesh;
generator_task->source_geometry_data = p_source_geometry_data;
generator_task->callback = p_callback;
generator_task->status = NavMeshGeneratorTask2D::TaskStatus::BAKING_STARTED;
generator_task->thread_task_id = WorkerThreadPool::get_singleton()->add_native_task(&NavMeshGenerator2D::generator_thread_bake, generator_task, NavMeshGenerator2D::baking_use_high_priority_threads, "NavMeshGeneratorBake2D");
generator_tasks.insert(generator_task->thread_task_id, generator_task);
generator_task_mutex.unlock();
}

bool NavMeshGenerator2D::is_baking(Ref<NavigationPolygon> p_navigation_polygon) {
Expand Down
10 changes: 3 additions & 7 deletions modules/navigation/3d/nav_mesh_generator_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void NavMeshGenerator3D::sync() {
return;
}

baking_navmesh_mutex.lock();
generator_task_mutex.lock();
MutexLock baking_navmesh_lock(baking_navmesh_mutex);
MutexLock generator_task_lock(generator_task_mutex);

LocalVector<WorkerThreadPool::TaskID> finished_task_ids;

Expand All @@ -124,9 +124,6 @@ void NavMeshGenerator3D::sync() {
for (WorkerThreadPool::TaskID finished_task_id : finished_task_ids) {
generator_tasks.erase(finished_task_id);
}

generator_task_mutex.unlock();
baking_navmesh_mutex.unlock();
}

void NavMeshGenerator3D::cleanup() {
Expand Down Expand Up @@ -223,15 +220,14 @@ void NavMeshGenerator3D::bake_from_source_geometry_data_async(Ref<NavigationMesh
baking_navmeshes.insert(p_navigation_mesh);
baking_navmesh_mutex.unlock();

generator_task_mutex.lock();
MutexLock generator_task_lock(generator_task_mutex);
NavMeshGeneratorTask3D *generator_task = memnew(NavMeshGeneratorTask3D);
generator_task->navigation_mesh = p_navigation_mesh;
generator_task->source_geometry_data = p_source_geometry_data;
generator_task->callback = p_callback;
generator_task->status = NavMeshGeneratorTask3D::TaskStatus::BAKING_STARTED;
generator_task->thread_task_id = WorkerThreadPool::get_singleton()->add_native_task(&NavMeshGenerator3D::generator_thread_bake, generator_task, NavMeshGenerator3D::baking_use_high_priority_threads, SNAME("NavMeshGeneratorBake3D"));
generator_tasks.insert(generator_task->thread_task_id, generator_task);
generator_task_mutex.unlock();
}

bool NavMeshGenerator3D::is_baking(Ref<NavigationMesh> p_navigation_mesh) {
Expand Down

0 comments on commit 0d0132b

Please sign in to comment.