[asterisk-commits] file: branch file/bridging r111850 - in /team/file/bridging: include/asterisk...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 15:37:20 CDT 2008


Author: file
Date: Fri Mar 28 15:37:20 2008
New Revision: 111850

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111850
Log:
Add bridge technology module reference counting.

Modified:
    team/file/bridging/include/asterisk/bridging.h
    team/file/bridging/main/bridging.c

Modified: team/file/bridging/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/file/bridging/include/asterisk/bridging.h?view=diff&rev=111850&r1=111849&r2=111850
==============================================================================
--- team/file/bridging/include/asterisk/bridging.h (original)
+++ team/file/bridging/include/asterisk/bridging.h Fri Mar 28 15:37:20 2008
@@ -97,6 +97,7 @@
 	int (*poke)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);                                                     /*! Callback for poking a bridge technology */
 	int formats;                                                                                                                           /*! Formats this bridge technology can support */
 	unsigned int suspended:1;                                                                                                              /*! Is this bridge technology suspended from use or not? */
+	struct ast_module *mod;                                                                                                                /*! Module this bridge technology belongs to */
 	AST_RWLIST_ENTRY(ast_bridge_technology) entry;                                                                                         /*! Linked list information */
 };
 
@@ -147,9 +148,12 @@
 
 /*! \brief Register a bridge technology for use
  * \param technology The bridge technology to register
- * \return Returns 0 on success, -1 on failure
- */
-int ast_bridge_technology_register(struct ast_bridge_technology *technology);
+ * \param module The module that is registering the bridge technology
+ * \return Returns 0 on success, -1 on failure
+ */
+#define ast_bridge_technology_register(technology) __ast_bridge_technology_register(technology, ast_module_info->self)
+
+int __ast_bridge_technology_register(struct ast_bridge_technology *technology, struct ast_module *mod);
 
 /*! \brief Unregister a bridge technology from use
  * \param technology The bridge technology to unregister

Modified: team/file/bridging/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/main/bridging.c?view=diff&rev=111850&r1=111849&r2=111850
==============================================================================
--- team/file/bridging/main/bridging.c (original)
+++ team/file/bridging/main/bridging.c Fri Mar 28 15:37:20 2008
@@ -38,6 +38,7 @@
 #include "asterisk/bridging.h"
 #include "asterisk/app.h"
 #include "asterisk/file.h"
+#include "asterisk/module.h"
 
 static AST_RWLIST_HEAD_STATIC(bridge_technologies, ast_bridge_technology);
 
@@ -46,9 +47,10 @@
 
 /*! \brief Register a bridge technology for use
  * \param technology The bridge technology to register
+ * \param module The module that is registering the bridge technology
  * \return Returns 0 on success, -1 on failure 
  */
-int ast_bridge_technology_register(struct ast_bridge_technology *technology)
+int __ast_bridge_technology_register(struct ast_bridge_technology *technology, struct ast_module *module)
 {
 	struct ast_bridge_technology *current = NULL;
 
@@ -68,6 +70,9 @@
 			return -1;
 		}
 	}
+
+	/* Copy module pointer so reference counting can keep the module from unloading */
+	technology->mod = module;
 
 	/* Insert our new bridge technology into the list and print out a pretty message */
 	AST_RWLIST_INSERT_TAIL(&bridge_technologies, technology, entry);
@@ -306,11 +311,16 @@
 		}
 		best = current;
 	}
+
+	if (best) {
+		/* Increment it's module reference count if present so it does not get unloaded while in use */
+		if (best->mod) {
+			ast_module_ref(best->mod);
+		}
+		ast_debug(1, "Chose bridge technology %s\n", best->name);
+	}
+
 	AST_RWLIST_UNLOCK(&bridge_technologies);
-
-	if (best) {
-		ast_debug(1, "Chose bridge technology %s\n", best->name);
-	}
 
 	return best;
 }
@@ -405,6 +415,11 @@
 		ast_debug(1, "Giving bridge technology %s the bridge structure %p to destroy\n", bridge->technology->name, bridge);
 		if (bridge->technology->destroy(bridge))
 			ast_debug(1, "Bridge technology %s failed to destroy bridge structure %p... trying our best\n", bridge->technology->name, bridge);
+	}
+
+	/* We are no longer using the bridge technology so decrement it's module reference count */
+	if (bridge->technology->mod) {
+		ast_module_unref(bridge->technology->mod);
 	}
 
 	/* Destroy the mutex that protects the bridge and the condition */
@@ -573,6 +588,11 @@
 		ast_debug(1, "Giving bridge technology %s the bridge structure %p (really %p) to destroy\n", old_technology->name, &temp_bridge, bridge);
 		if (old_technology->destroy(&temp_bridge))
 			ast_debug(1, "Bridge technology %s failed to destroy bridge structure %p (really %p)... some memory may have leaked\n", old_technology->name, &temp_bridge, bridge);
+	}
+
+	/* Since the old technology is no longer being used decrement it's module reference count */
+	if (old_technology->mod) {
+		ast_module_unref(old_technology->mod);
 	}
 
 	/* If the new technology needs a thread and we were called when a channel hung up start one up */




More information about the asterisk-commits mailing list