]> 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)
committerGeorge Joseph <gjoseph@sangoma.com>
Wed, 17 Sep 2025 19:36:51 +0000 (13:36 -0600)
commit850692b52f6b996c90888c14578db8ff568ad7e5
tree72daed65cf1b323991d64bd627be7cfc07b59bd2
parente91aedd3856e2195adc979405f115a88aec61384
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