]> git.ipfire.org Git - thirdparty/asterisk.git/commit
channelstorage_cpp_map_name_id.cc: Refactor iterators for thread-safety.
authorGeorge Joseph <gjoseph@sangoma.com>
Wed, 30 Jul 2025 12:39:49 +0000 (06:39 -0600)
committerAsterisk Development Team <asteriskteam@digium.com>
Wed, 10 Sep 2025 19:55:23 +0000 (19:55 +0000)
commite19edb28ffc441c1087a0ee6e578ffdf2f8aca5a
tree9cee29ae799736f39e5331cbcff5df6930d37259
parentde268d3e98f002a13a68b404aabad99b9f343c5f
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
(cherry picked from commit e50d0cf741b9c740ac5da0a41af1cf79b644d224)
main/channelstorage.c
main/channelstorage_cpp_map_name_id.cc