diff options
author | David M. Lee <dlee@digium.com> | 2013-08-16 16:03:34 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-08-16 16:03:34 +0000 |
commit | f29d969a7969b1122b5039747550c1cb039abd23 (patch) | |
tree | 1a58f7d5b3da514304442e9e596c22008a66c62e /include | |
parent | a4ffa9f72b3ae9d26d8b190fd05f4f21c6c3544b (diff) |
Stasis: address refcount races; implementation comments
Change r395954 reordered some stasis object destruction, which should
have been fine. Unfortunately, it caused some hard to reproduce issues
related to objects being accessed after they had been destroyed. The
patch in r396329 fixed the destruction order problem; this patch
addresses the underlying issue. A few other stasis-related fixes were
also added.
* Add ref-bumps around areas where objects may get transitively
destroyed. (For example, where we lock a topic, unref a subscription,
which unrefs the topic, which explodes the topic when we try to
unlock it.)
* Wrote an extensive doxygen page about Stasis implementation,
relationships between objects, lifecycles of objects, how the
refcounting works, etc. Many other comments were added, corrected, or
cleaned up.
* Added an assert to the topic dtor to catch extra ref decrements.
* Fixed type used after destruction errors for graceful shutdown in
stasis_channels.c.
* I added two unit tests in an attempt to catch destruction order
issues. Since the underlying cause is a race condition, though, the
tests rarely failed even when the code was wrong.
* Fixed a leak in stasis_cache_pattern.c.
(closes issue ASTERISK-22243)
Review: https://reviewboard.asterisk.org/r/2746/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396842 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/astobj2.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index b43c5ee94..933092fe6 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -510,6 +510,25 @@ void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned in #endif +/*! + * \since 12 + * \brief Bump refcount on an AO2 object by one, returning the object. + * + * This is useful for inlining a ref bump, and you don't care about the ref + * count. Also \c NULL safe, for even more convenience. + * + * \param obj AO2 object to bump the refcount on. + * \retval The given \a obj pointer. + */ +#define ao2_bump(obj) \ + ({ \ + typeof(obj) __obj_ ## __LINE__ = (obj); \ + if (__obj_ ## __LINE__) { \ + ao2_ref(__obj_ ## __LINE__, +1); \ + } \ + __obj_ ## __LINE__; \ + }) + int __ao2_ref_debug(void *o, int delta, const char *tag, const char *file, int line, const char *func); int __ao2_ref(void *o, int delta); |