Fix caching topic shutdown assertions
authorDavid M. Lee <dlee@digium.com>
Thu, 18 Jul 2013 14:08:21 +0000 (14:08 +0000)
committerDavid M. Lee <dlee@digium.com>
Thu, 18 Jul 2013 14:08:21 +0000 (14:08 +0000)
commitde68dabb97151b334c1cbb73ee6ac0d0aecd3ed9
treed75137f019f9429887247c1d801a1ffd1ef0ee24
parent6d9909887e5e2005a4cadd44ff9d1323857d6f60
Fix caching topic shutdown assertions

The recent changes to update stasis_cache_topics directly from the
publisher thread uncovered a race condition, which was causing asserts
in the /stasis/core tests.

If the caching topic's subscription is the last reference to the
caching topic, it will destroy the caching topic after the final
message has been processed. When dispatching to a different thread,
this usually gave the unsubscribe enough time to finish before
destruction happened. Now, however, it consistently destroys before
unsubscription is complete.

This patch adds an extra reference to the caching topic, to hold it
for the duration of the unsubscription.

This patch also removes an extra unref that was happening when the
final message was received by the caching topic. It was put there
because of an extra ref that was put into the caching topic's
constructor. Both have been removed, which makes the destructor a bit
less confusing.

Review: https://reviewboard.asterisk.org/r/2675/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394686 65c4cc65-6c06-0410-ace0-fbb531ad65f3
main/stasis_cache.c