[asterisk-commits] file: branch file/sorceryx2 r381844 - in /team/file/sorceryx2: include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 20 17:11:25 CST 2013


Author: file
Date: Wed Feb 20 17:11:21 2013
New Revision: 381844

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381844
Log:
Store whether an object is a unique instance or not. This can be used to reduce expensive object copying.

Modified:
    team/file/sorceryx2/include/asterisk/sorcery.h
    team/file/sorceryx2/main/sorcery.c
    team/file/sorceryx2/res/res_sorcery_config.c
    team/file/sorceryx2/res/res_sorcery_memory.c
    team/file/sorceryx2/tests/test_sorcery.c

Modified: team/file/sorceryx2/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx2/include/asterisk/sorcery.h?view=diff&rev=381844&r1=381843&r2=381844
==============================================================================
--- team/file/sorceryx2/include/asterisk/sorcery.h (original)
+++ team/file/sorceryx2/include/asterisk/sorcery.h Wed Feb 20 17:11:21 2013
@@ -223,6 +223,9 @@
 
 	/*! \brief Type of object */
 	char type[MAX_OBJECT_TYPE];
+
+	/*! \brief Set if the object is a unique unshared instance */
+	unsigned int unique:1;
 };
 
 /*! \brief Macro which must be used at the beginning of each sorcery capable object */
@@ -612,6 +615,25 @@
  */
 const char *ast_sorcery_object_get_type(const void *object);
 
+/*!
+ * \brief Clears the unique bit of an object
+ *
+ * \param object Pointer to a sorcery object
+ *
+ * \note This should only be used by wizards when storing the object
+ */
+void ast_sorcery_object_clear_unique(void *object);
+
+/*!
+ * \brief Tests whether an object is a unique instance or not
+ *
+ * \param object Pointer to a sorcery object
+ *
+ * \retval 0 if not unique
+ * \retval 1 if unique
+ */
+unsigned int ast_sorcery_object_is_unique(const void *object);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/file/sorceryx2/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx2/main/sorcery.c?view=diff&rev=381844&r1=381843&r2=381844
==============================================================================
--- team/file/sorceryx2/main/sorcery.c (original)
+++ team/file/sorceryx2/main/sorcery.c Wed Feb 20 17:11:21 2013
@@ -806,6 +806,8 @@
 		return NULL;
 	}
 
+	details->unique = 1;
+
 	return details;
 }
 
@@ -1070,3 +1072,15 @@
 	const struct ast_sorcery_object_details *details = object;
 	return details->type;
 }
+
+void ast_sorcery_object_clear_unique(void *object)
+{
+	struct ast_sorcery_object_details *details = object;
+	details->unique = 0;
+}
+
+unsigned int ast_sorcery_object_is_unique(const void *object)
+{
+	const struct ast_sorcery_object_details *details = object;
+	return details->unique;
+}

Modified: team/file/sorceryx2/res/res_sorcery_config.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx2/res/res_sorcery_config.c?view=diff&rev=381844&r1=381843&r2=381844
==============================================================================
--- team/file/sorceryx2/res/res_sorcery_config.c (original)
+++ team/file/sorceryx2/res/res_sorcery_config.c Wed Feb 20 17:11:21 2013
@@ -284,6 +284,7 @@
 			}
 		}
 
+		ast_sorcery_object_clear_unique(obj);
 		ao2_link_flags(objects, obj, OBJ_NOLOCK);
 	}
 

Modified: team/file/sorceryx2/res/res_sorcery_memory.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx2/res/res_sorcery_memory.c?view=diff&rev=381844&r1=381843&r2=381844
==============================================================================
--- team/file/sorceryx2/res/res_sorcery_memory.c (original)
+++ team/file/sorceryx2/res/res_sorcery_memory.c Wed Feb 20 17:11:21 2013
@@ -98,6 +98,7 @@
 
 static int sorcery_memory_create(void *data, void *object)
 {
+	ast_sorcery_object_clear_unique(object);
 	ao2_link(data, object);
 	return 0;
 }
@@ -195,6 +196,7 @@
 		return -1;
 	}
 
+	ast_sorcery_object_clear_unique(object);
 	ao2_link(data, object);
 
 	ao2_unlock(data);

Modified: team/file/sorceryx2/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx2/tests/test_sorcery.c?view=diff&rev=381844&r1=381843&r2=381844
==============================================================================
--- team/file/sorceryx2/tests/test_sorcery.c (original)
+++ team/file/sorceryx2/tests/test_sorcery.c Wed Feb 20 17:11:21 2013
@@ -1171,6 +1171,9 @@
 
 	if (ast_sorcery_create(sorcery, obj)) {
 		ast_test_status_update(test, "Failed to create object using in-memory wizard\n");
+		return AST_TEST_FAIL;
+	} else if (ast_sorcery_object_is_unique(obj)) {
+		ast_test_status_update(test, "Object is marked as unique when it should not be\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1830,6 +1833,9 @@
 		return AST_TEST_FAIL;
 	} else if (obj->joe != 41) {
 		ast_test_status_update(test, "Value of 'joe' on object is not what is configured in configuration file\n");
+		return AST_TEST_FAIL;
+	} else if (ast_sorcery_object_is_unique(obj)) {
+		ast_test_status_update(test, "Object is marked as unique when it should not be\n");
 		return AST_TEST_FAIL;
 	}
 




More information about the asterisk-commits mailing list