[svn-commits] dlee: branch dlee/ASTERISK-22243 r396344 - in /team/dlee/ASTERISK-22243: incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 6 14:35:44 CDT 2013


Author: dlee
Date: Tue Aug  6 14:35:42 2013
New Revision: 396344

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396344
Log:
Ref-bump topics when locking them.

Modified:
    team/dlee/ASTERISK-22243/include/asterisk/astobj2.h
    team/dlee/ASTERISK-22243/main/stasis.c

Modified: team/dlee/ASTERISK-22243/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22243/include/asterisk/astobj2.h?view=diff&rev=396344&r1=396343&r2=396344
==============================================================================
--- team/dlee/ASTERISK-22243/include/asterisk/astobj2.h (original)
+++ team/dlee/ASTERISK-22243/include/asterisk/astobj2.h Tue Aug  6 14:35:42 2013
@@ -509,6 +509,22 @@
 #define ao2_ref(o,delta)       __ao2_ref((o), (delta))
 
 #endif
+
+/*!
+ * \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.
+ *
+ * \param obj AO2 object
+ * \retval The given \a obj pointer.
+ */
+#define ao2_ref1(obj)				\
+	({					\
+		typeof(obj) __obj = (obj);	\
+		ao2_ref(__obj, +1);		\
+		__obj;				\
+	})
 
 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);

Modified: team/dlee/ASTERISK-22243/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22243/main/stasis.c?view=diff&rev=396344&r1=396343&r2=396344
==============================================================================
--- team/dlee/ASTERISK-22243/main/stasis.c (original)
+++ team/dlee/ASTERISK-22243/main/stasis.c Tue Aug  6 14:35:42 2013
@@ -232,7 +232,10 @@
 {
 	if (sub) {
 		size_t i;
-		struct stasis_topic *topic = sub->topic;
+		/* The subscription may be the last ref to this topic. Hold
+		 * the topic ref open until after the unlock. */
+		RAII_VAR(struct stasis_topic *, topic, ao2_ref1(sub->topic),
+			ao2_cleanup);
 		SCOPED_AO2LOCK(lock_topic, topic);
 
 		for (i = 0; i < topic->num_subscribers_current; ++i) {
@@ -424,9 +427,13 @@
 	return 0;
 }
 
-void stasis_forward_message(struct stasis_topic *topic, struct stasis_topic *publisher_topic, struct stasis_message *message)
+void stasis_forward_message(struct stasis_topic *t, struct stasis_topic *publisher_topic, struct stasis_message *message)
 {
 	size_t i;
+	/* The dispatch may dispose of the final reference to the topic. Hold
+	 * it open until after the unlock.
+	 */
+	RAII_VAR(struct stasis_topic *, topic, ao2_ref1(t), ao2_cleanup);
 	SCOPED_AO2LOCK(lock, topic);
 
 	ast_assert(topic != NULL);




More information about the svn-commits mailing list