[asterisk-commits] dlee: branch dlee/stasis-vtable r390176 - in /team/dlee/stasis-vtable: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 30 22:11:10 CDT 2013


Author: dlee
Date: Thu May 30 22:11:07 2013
New Revision: 390176

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390176
Log:
Finally added ao2_ref1

Modified:
    team/dlee/stasis-vtable/include/asterisk/astobj2.h
    team/dlee/stasis-vtable/tests/test_astobj2.c

Modified: team/dlee/stasis-vtable/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/include/asterisk/astobj2.h?view=diff&rev=390176&r1=390175&r2=390176
==============================================================================
--- team/dlee/stasis-vtable/include/asterisk/astobj2.h (original)
+++ team/dlee/stasis-vtable/include/asterisk/astobj2.h Thu May 30 22:11:07 2013
@@ -509,6 +509,35 @@
 #define ao2_ref(o,delta)       __ao2_ref((o), (delta))
 
 #endif
+
+/*!
+ * \brief Convenient, \c NULL safe wrapper for ao2_ref(obj, +1).
+ *
+ * \param o Object to bump refcount on, or \c NULL.
+ */
+#define ao2_ref1(o)						\
+	({							\
+		typeof((o)) __obj_ ## __LINE__ = (o);		\
+		if (__obj_ ## __LINE__) {			\
+			ao2_ref(__obj_ ## __LINE__, +1);	\
+		}						\
+		__obj_ ## __LINE__;				\
+	})
+
+/*!
+ * \brief Convenient, \c NULL safe wrapper for ao2_ref(obj, +1).
+ *
+ * \param o Object to bump refcount on, or \c NULL.
+ * \param tag Debug tag.
+ */
+#define ao2_t_ref1(o,tag)						\
+	({								\
+		typeof((o)) __obj_ ## __LINE__ = (o);			\
+		if (__obj_ ## __LINE__) {				\
+			ao2_t_ref(__obj_ ## __LINE__, +1, (tag));	\
+		}							\
+		__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);

Modified: team/dlee/stasis-vtable/tests/test_astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/tests/test_astobj2.c?view=diff&rev=390176&r1=390175&r2=390176
==============================================================================
--- team/dlee/stasis-vtable/tests/test_astobj2.c (original)
+++ team/dlee/stasis-vtable/tests/test_astobj2.c Thu May 30 22:11:07 2013
@@ -2059,12 +2059,42 @@
 	return res;
 }
 
+AST_TEST_DEFINE(astobj2_ref1)
+{
+	RAII_VAR(void *, obj, NULL, ao2_cleanup);
+	RAII_VAR(void *, refed_obj, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "astobj2_ref1";
+		info->category = "/main/astobj2/";
+		info->summary = "Test the ao2_ref1 macro";
+		info->description =
+			"This test determines if the ao2_ref1 macro works as "
+			"expected.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	obj = ao2_alloc(1, NULL);
+	ast_test_validate(test, NULL != obj);
+	ast_test_validate(test, 1 == ao2_ref(obj, 0));
+
+	refed_obj = ao2_ref1(obj);
+	ast_test_validate(test, obj == refed_obj);
+	ast_test_validate(test, 2 == ao2_ref(obj, 0));
+
+	return AST_TEST_PASS;
+}
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(astobj2_test_1);
 	AST_TEST_UNREGISTER(astobj2_test_2);
 	AST_TEST_UNREGISTER(astobj2_test_3);
 	AST_TEST_UNREGISTER(astobj2_test_4);
+	AST_TEST_UNREGISTER(astobj2_ref1);
 	return 0;
 }
 
@@ -2074,6 +2104,7 @@
 	AST_TEST_REGISTER(astobj2_test_2);
 	AST_TEST_REGISTER(astobj2_test_3);
 	AST_TEST_REGISTER(astobj2_test_4);
+	AST_TEST_REGISTER(astobj2_ref1);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list