enh(core): prevent slots being called when slot owner has been already destroyed
Description
In rare situation, a slot can be called when the slot owner is already destroyed. This theoretically could happen because the slot is itself a shared pointer detached from the object that holds the real slot function.
Functional specifications
Just store an optional std::weak_ptr that references the owner in Slot<std::function<R(A ...)>
(in libs/core/core/com/Slot.hpp
). Test if we can get a lock before calling Slot::run(A ... a)
and Slot::call(A ... a)
. Throw an exception if the lock cannot be obtained.
Test plan
- Unit test