Skip to content

Commit a21824b

Browse files
committed
Merge pull request #85295 from jsjtxietian/use-mutex-protect-max_index-in-ImportThreadData
Use `SafeNumeric` to protect `max_index` in ImportThreadData
2 parents bbb8667 + 4861ab4 commit a21824b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

editor/editor_file_system.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,8 +2328,9 @@ void EditorFileSystem::reimport_file_with_custom_parameters(const String &p_file
23282328
}
23292329

23302330
void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) {
2331-
p_import_data->max_index = MAX(p_import_data->reimport_from + int(p_index), p_import_data->max_index);
2332-
_reimport_file(p_import_data->reimport_files[p_import_data->reimport_from + p_index].path);
2331+
int current_max = p_import_data->reimport_from + int(p_index);
2332+
p_import_data->max_index.exchange_if_greater(current_max);
2333+
_reimport_file(p_import_data->reimport_files[current_max].path);
23332334
}
23342335

23352336
void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
@@ -2409,15 +2410,15 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
24092410
importer->import_threaded_begin();
24102411

24112412
ImportThreadData tdata;
2412-
tdata.max_index = from;
2413+
tdata.max_index.set(from);
24132414
tdata.reimport_from = from;
24142415
tdata.reimport_files = reimport_files.ptr();
24152416

24162417
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));
24172418
int current_index = from - 1;
24182419
do {
2419-
if (current_index < tdata.max_index) {
2420-
current_index = tdata.max_index;
2420+
if (current_index < tdata.max_index.get()) {
2421+
current_index = tdata.max_index.get();
24212422
pr.step(reimport_files[current_index].path.get_file(), current_index);
24222423
}
24232424
OS::get_singleton()->delay_usec(1);

editor/editor_file_system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class EditorFileSystem : public Node {
282282
struct ImportThreadData {
283283
const ImportFile *reimport_files;
284284
int reimport_from;
285-
int max_index = 0;
285+
SafeNumeric<int> max_index;
286286
};
287287

288288
void _reimport_thread(uint32_t p_index, ImportThreadData *p_import_data);

0 commit comments

Comments
 (0)