]> git.ipfire.org Git - thirdparty/asterisk.git/commit
channelstorage_cpp_map_name_id.cc: Refactor iterators for thread-safety. master
authorGeorge Joseph <gjoseph@sangoma.com>
Wed, 30 Jul 2025 12:39:49 +0000 (06:39 -0600)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 7 Aug 2025 14:58:32 +0000 (14:58 +0000)
commitbaa73b6b1207b9bc634b1554dce290027782e20b
tree9ee0f379787ad6f05031d1f3f844d270dfd1e12c
parent22d405e900e02e5076c4f4b3572352b9fc5b07f8
channelstorage_cpp_map_name_id.cc: Refactor iterators for thread-safety.

The fact that deleting an object from a map invalidates any iterator
that happens to currently point to that object was overlooked in the initial
implementation.  Unfortunately, there's no way to detect that an iterator
has been invalidated so the result was an occasional SEGV triggered by modules
like app_chanspy that opens an iterator and can keep it open for a long period
of time.  The new implementation doesn't keep the underlying C++ iterator
open across calls to ast_channel_iterator_next() and uses a read lock
on the map to ensure that, even for the few microseconds we use the
iterator, another thread can't delete a channel from under it.  Even with
this change, the iterators are still WAY faster than the ao2_legacy
storage driver.

Full details about the new implementation are located in the comments for
iterator_next() in channelstorage_cpp_map_name_id.cc.

Resolves: #1309
main/channelstorage.c
main/channelstorage_cpp_map_name_id.cc