You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support users holding onto shared pointers in the message memory pool (ros2#2336)
* Support users holding onto shared pointers in the message memory pool
Before this commit, the MessageMemoryPool would actually
reuse messages in the pool, even if the user had taken
additional shared_ptr copies.
This commit fixes things so that we properly handle that situation. In particular,
we allocate memory during class initialization, and delete
it during destruction. We then run the constructor when
we hand the pointer out, and the destructor (only) when
we return it to the pool. This keeps things consistent.
We also add in locks, since in a multi-threaded scenario we need
to protect against multiple threads accessing the pool
at the same time.
With this in place, things work as expected when users hold
shared_ptr copies. We also add in a test for this situation.
One note about performance: this update preserves the
"no-allocations-at-runtime" aspect of the MessagePool. However,
there are some tradeoffs with CPU time here, particularly with
very large message pools. This could probably be optimized
further to do less work when trying to add items back to the
free_list, but I view that as a further enhancement.
Signed-off-by: Chris Lalancette <[email protected]>
0 commit comments