Add thread safety to Object signals

* It turns out the majority of this work was done already by AThousandShips as part of #89451. This allows to do lock-less emitting of signals.
* This means, that only the signal map needs to be protected, making the task simple and without risk of deadlocks, or affecting performance.
* Objects can choose to not protect signals for performance (as example Node uses thread guards for protection, so these signals are not thread safe).
This commit is contained in:
Juan 2025-04-16 15:28:41 +02:00
parent dbddc9ef29
commit 2f39d8ebef
4 changed files with 128 additions and 60 deletions

View file

@ -608,7 +608,8 @@ private:
HashMap<Callable, Slot, HashableHasher<Callable>> slot_map;
bool removable = false;
};
friend struct _ObjectSignalLock;
mutable Mutex *signal_mutex = nullptr;
HashMap<StringName, SignalData> signal_map;
List<Connection> connections;
#ifdef DEBUG_ENABLED
@ -756,6 +757,8 @@ protected:
bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false);
virtual bool _uses_signal_mutex() const;
#ifdef TOOLS_ENABLED
struct VirtualMethodTracker {
void **method;