summaryrefslogtreecommitdiffstats
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
authorjsjtxietian <jsjtxietian@outlook.com>2023-11-24 14:58:41 +0800
committerjsjtxietian <jsjtxietian@outlook.com>2023-11-28 12:50:57 +0800
commit4861ab4cfe59d791b2f97f20a4fcf576fe661685 (patch)
tree7e9aa461c1d92194eae1353debe8736b067bd785 /editor/editor_file_system.cpp
parent80de898d721f952dac0b102d48bb73d6b02ee1e8 (diff)
downloadredot-engine-4861ab4cfe59d791b2f97f20a4fcf576fe661685.tar.gz
Use mutex to protect max_index in ImportThreadData
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index e81f71e0e0..585ed15843 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -2211,8 +2211,9 @@ void EditorFileSystem::reimport_file_with_custom_parameters(const String &p_file
}
void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) {
- p_import_data->max_index = MAX(p_import_data->reimport_from + int(p_index), p_import_data->max_index);
- _reimport_file(p_import_data->reimport_files[p_import_data->reimport_from + p_index].path);
+ int current_max = p_import_data->reimport_from + int(p_index);
+ p_import_data->max_index.exchange_if_greater(current_max);
+ _reimport_file(p_import_data->reimport_files[current_max].path);
}
void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
@@ -2288,15 +2289,15 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
importer->import_threaded_begin();
ImportThreadData tdata;
- tdata.max_index = from;
+ tdata.max_index.set(from);
tdata.reimport_from = from;
tdata.reimport_files = reimport_files.ptr();
WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &EditorFileSystem::_reimport_thread, &tdata, i - from + 1, -1, false, vformat(TTR("Import resources of type: %s"), reimport_files[from].importer));
int current_index = from - 1;
do {
- if (current_index < tdata.max_index) {
- current_index = tdata.max_index;
+ if (current_index < tdata.max_index.get()) {
+ current_index = tdata.max_index.get();
pr.step(reimport_files[current_index].path.get_file(), current_index);
}
OS::get_singleton()->delay_usec(1);