]> 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 17:40:38 +0000 (11:40 -0600)
commiteb1ede461295e4a092601d28699f670ece41e13c
treefa49d985732b9c85327fcdda61f40c6409d194b8
parent4b01b0efd95779236d96daea439863cc25da9595
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 06622f310b367fc18f2332bf7f83f28b9d8c325b)
main/channelstorage.c
main/channelstorage_cpp_map_name_id.cc