QuantumLeaps / qpcpp

QP/C++ Real-Time Embedded Framework/RTOS for embedded systems based on active objects (actors) and hierarchical state machines
https://www.state-machine.com/products/qp
371 stars 82 forks source link

QF::newRef_ Should Support Static Events (Non-dynamic Events) #7

Closed DanielLyubin closed 3 years ago

DanielLyubin commented 3 years ago

Currently this function allows only dynamic events to add a new reference and increment the reference count. This is problematic because we have a use case where there are two possible sources for the same event - one sends a static event and one sends a dynamic one. The target AO needs to save the event pointer to use the event forever. The source is determined during run time. Current implementation forces me to check if the event is dynamic or not, instead of the function.

A suitable solution would be checking if the event is dynamic. If it is, increment the ref. count. Otherwise, do nothing.

quantum-leaps commented 3 years ago

The Q_NEW_REF() API is an advanced optimization, which is intended to be used only for frequent dynamic events, where such optimization is actually worth it. In all other cases, any information from an event that is needed beyond the current RTC step should be simply copied into the private data of the AO.

The QF::newRef_(), which underlines the Q_NEW_REF() macro, already asserts that the event is dynamic. This is exactly per the intent.

--MMS

DanielLyubin commented 3 years ago

I understand why it's needed. I'm saying that it needs to support non-dynamic events., i.e remove the assert

quantum-leaps commented 3 years ago

I'm not sure if removing the assert is a good idea. Without the asset the "event-reference" mechanism could be abused for static events.