[asterisk-commits] twilson: branch twilson/config_work r366166 - in /team/twilson/config_work: i...

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


Author: twilson
Date: Thu May 10 15:30:08 2012
New Revision: 366166

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366166
Log:
Round out the locking functions for ao2 global objects

Modified:
    team/twilson/config_work/include/asterisk/astobj2.h
    team/twilson/config_work/main/astobj2.c
    team/twilson/config_work/main/config_options.c

Modified: team/twilson/config_work/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/astobj2.h?view=diff&rev=366166&r1=366165&r2=366166
==============================================================================
--- team/twilson/config_work/include/asterisk/astobj2.h (original)
+++ team/twilson/config_work/include/asterisk/astobj2.h Thu May 10 15:30:08 2012
@@ -694,8 +694,42 @@
 	__ao2_global_obj_replace_unref(&array.global, (idx), (obj), 1, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
 int __ao2_global_obj_replace_unref(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name);
 
-#define __ao2_global_obj_wrlock(array) __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, &array->lock, #array)
-#define __ao2_global_obj_unlock(array) __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, &array->lock, #array)
+/*!
+ * \brief Write-lock a global object array
+ * \since 11.0
+ *
+ * \param array The array to lock
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+#define ao2_global_obj_wrlock(array) __ao2_global_obj_wrlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
+int __ao2_global_obj_wrlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
+
+/*!
+ * \brief Read-lock a global object array
+ * \since 11.0
+ *
+ * \param array The array to lock
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+#define ao2_global_obj_rdlock(array) __ao2_global_obj_wrlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
+int __ao2_global_obj_rdlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
+
+/*!
+ * \brief Unlock a global object array
+ * \since 11.0
+ *
+ * param array The array to unlock
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+#define ao2_global_obj_unlock(array) __ao2_global_obj_unlock(&array.global, __FILE__, __LINE__, __PRETTY_FUNCTION__, #array)
+int __ao2_global_obj_unlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name);
+
 /*!
  * \brief Get a reference to the object stored in the ao2 global array.
  * \since 11.0

Modified: team/twilson/config_work/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/astobj2.c?view=diff&rev=366166&r1=366165&r2=366166
==============================================================================
--- team/twilson/config_work/main/astobj2.c (original)
+++ team/twilson/config_work/main/astobj2.c Thu May 10 15:30:08 2012
@@ -642,7 +642,7 @@
 		/* For sanity */
 		return;
 	}
-	if (__ast_rwlock_wrlock(file, line, func, &array->lock, name)) {
+	if (__ao2_global_obj_wrlock(array, file, line, func, name)) {
 		/* Could not get the write lock. */
 		return;
 	}
@@ -656,7 +656,7 @@
 		}
 	}
 
-	__ast_rwlock_unlock(file, line, func, &array->lock, name);
+	__ao2_global_obj_unlock(array, file, line, func, name);
 }
 
 void *__ao2_global_obj_replace(struct ao2_global_obj *array, unsigned int idx, void *obj, int lock, const char *tag, const char *file, int line, const char *func, const char *name)
@@ -667,7 +667,7 @@
 		/* For sanity */
 		return NULL;
 	}
-	if (lock && __ast_rwlock_wrlock(file, line, func, &array->lock, name)) {
+	if (lock && __ao2_global_obj_wrlock(array, file, line, func, name)) {
 		/* Could not get the write lock. */
 		return NULL;
 	}
@@ -679,7 +679,7 @@
 	array->obj[idx] = obj;
 
 	if (lock) {
-		__ast_rwlock_unlock(file, line, func, &array->lock, name);
+		__ao2_global_obj_unlock(array, file, line, func, name);
 	}
 
 	return obj_old;
@@ -695,6 +695,21 @@
 	return 0;
 }
 
+int __ao2_global_obj_wrlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
+{
+	return __ast_rwlock_wrlock(file, line, func, &array->lock, name);
+}
+
+int __ao2_global_obj_rdlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
+{
+	return __ast_rwlock_rdlock(file, line, func, &array->lock, name);
+}
+
+int __ao2_global_obj_unlock(struct ao2_global_obj *array, const char *file, int line, const char *func, const char *name)
+{
+	return __ast_rwlock_unlock(file, line, func, &array->lock, name);
+}
+
 void *__ao2_global_obj_ref(struct ao2_global_obj *array, unsigned int idx, const char *tag, const char *file, int line, const char *func, const char *name)
 {
 	void *obj;
@@ -703,7 +718,7 @@
 		/* For sanity */
 		return NULL;
 	}
-	if (__ast_rwlock_rdlock(file, line, func, &array->lock, name)) {
+	if (__ao2_global_obj_rdlock(array, file, line, func, name)) {
 		/* Could not get the read lock. */
 		return NULL;
 	}
@@ -713,11 +728,10 @@
 		__ao2_ref_debug(obj, +1, tag, file, line, func);
 	}
 
-	__ast_rwlock_unlock(file, line, func, &array->lock, name);
+	__ao2_global_obj_unlock(array, file, line, func, name);
 
 	return obj;
 }
-
 
 /* internal callback to destroy a container. */
 static void container_destruct(void *c);

Modified: team/twilson/config_work/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/config_options.c?view=diff&rev=366166&r1=366165&r2=366166
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Thu May 10 15:30:08 2012
@@ -359,11 +359,11 @@
 {
 	size_t x;
 
-	__ao2_global_obj_wrlock(info->current_array);
+	__ao2_global_obj_wrlock(info->current_array, __FILE__, __LINE__, __PRETTY_FUNCTION__, "info->current_array");
 	for (x = 0; x < info->current_array->num_elements; x++) {
-		__ao2_global_obj_replace_unref(info->current_array, x, info->new_array[x], 0, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, "bob");
-	}
-	__ao2_global_obj_unlock(info->current_array);
+		__ao2_global_obj_replace_unref(info->current_array, x, info->new_array[x], 0, "", __FILE__, __LINE__, __PRETTY_FUNCTION__, "unused");
+	}
+	__ao2_global_obj_unlock(info->current_array, __FILE__, __LINE__, __PRETTY_FUNCTION__, "info->current_array");
 
 	return 0;
 }




More information about the asterisk-commits mailing list