From bfe66ab7cd73279d078d73b925573745031a9e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Wed, 22 Nov 2023 23:20:49 +0100 Subject: [PATCH] Fixup thread-owned lambda bookkeeping on thread exit (take 2) --- core/templates/list.h | 39 ++++++++++++++++ modules/gdscript/gdscript.cpp | 87 +++++++++++++++++++++++++++++------ modules/gdscript/gdscript.h | 20 ++++++-- 3 files changed, 129 insertions(+), 17 deletions(-) diff --git a/core/templates/list.h b/core/templates/list.h index 6393b942ff1..354e826a432 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -132,6 +132,8 @@ public: data->erase(this); } + void transfer_to_back(List *p_dst_list); + _FORCE_INLINE_ Element() {} }; @@ -762,4 +764,41 @@ public: } }; +template +void List::Element::transfer_to_back(List *p_dst_list) { + // Detach from current. + + if (data->first == this) { + data->first = data->first->next_ptr; + } + if (data->last == this) { + data->last = data->last->prev_ptr; + } + if (prev_ptr) { + prev_ptr->next_ptr = next_ptr; + } + if (next_ptr) { + next_ptr->prev_ptr = prev_ptr; + } + data->size_cache--; + + // Attach to the back of the new one. + + if (!p_dst_list->_data) { + p_dst_list->_data = memnew_allocator(_Data, A); + p_dst_list->_data->first = this; + p_dst_list->_data->last = nullptr; + p_dst_list->_data->size_cache = 0; + prev_ptr = nullptr; + } else { + p_dst_list->_data->last->next_ptr = this; + prev_ptr = p_dst_list->_data->last; + } + p_dst_list->_data->last = this; + next_ptr = nullptr; + + data = p_dst_list->_data; + p_dst_list->_data->size_cache++; +} + #endif // LIST_H diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index a2be6a86d73..05c25584177 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1391,36 +1391,54 @@ String GDScript::debug_get_script_name(const Ref