[asterisk-commits] russell: branch russell/cdr-q r254002 - in /team/russell/cdr-q: include/aster...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 23 14:27:44 CDT 2010


Author: russell
Date: Tue Mar 23 14:27:40 2010
New Revision: 254002

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=254002
Log:
Add module ref counting.

Modified:
    team/russell/cdr-q/include/asterisk/cdr.h
    team/russell/cdr-q/main/cdr.c

Modified: team/russell/cdr-q/include/asterisk/cdr.h
URL: http://svnview.digium.com/svn/asterisk/team/russell/cdr-q/include/asterisk/cdr.h?view=diff&rev=254002&r1=254001&r2=254002
==============================================================================
--- team/russell/cdr-q/include/asterisk/cdr.h (original)
+++ team/russell/cdr-q/include/asterisk/cdr.h Tue Mar 23 14:27:40 2010
@@ -197,8 +197,12 @@
  *
  * \since 1.8
  */
-struct ast_cdr_backend *ast_cdr_register_sink(const char *name, const char *desc,
-		const char *unique_id, ast_cdr_sink_cb sink_cb, void *data);
+#define ast_cdr_register_sink(name, desc, unique_id, sink_cb, data) \
+	__ast_cdr_register_sink(name, desc, unique_id, sink_cb, data, ast_module_info->self)
+
+struct ast_cdr_backend *__ast_cdr_register_sink(const char *name, const char *desc,
+		const char *unique_id, ast_cdr_sink_cb sink_cb, void *data,
+		struct ast_module *mod);
 
 /*!
  * \brief Unregister a sink for posting CDRs

Modified: team/russell/cdr-q/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/russell/cdr-q/main/cdr.c?view=diff&rev=254002&r1=254001&r2=254002
==============================================================================
--- team/russell/cdr-q/main/cdr.c (original)
+++ team/russell/cdr-q/main/cdr.c Tue Mar 23 14:27:40 2010
@@ -40,6 +40,7 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/module.h"
 
 /*!
  * \brief Hack to be able to link a CDR struct into a list head
@@ -115,6 +116,10 @@
 	 * \brief The last timestamp of a post failure log entry
 	 */
 	struct timeval last_error;
+	/*!
+	 * \brief The module that registered this backend (if available)
+	 */
+	struct ast_module *mod;
 };
 
 /*!
@@ -296,7 +301,8 @@
  */
 static struct ast_cdr_backend *cdr_backend_register(enum cdr_backend_type type,
 		union cdr_backend_cb cb, void *data,
-		const char *name, const char *desc, const char *unique_id)
+		const char *name, const char *desc, const char *unique_id,
+		struct ast_module *mod)
 {
 	struct ast_cdr_backend *backend;
 	char tps_name[128];
@@ -353,21 +359,23 @@
 	backend->type = type;
 	backend->cb = cb;
 	backend->cb_data = data;
+	backend->mod = mod;
 
 	ao2_link(cdr_backends, backend);
 
 	return backend;
 }
 
-struct ast_cdr_backend *ast_cdr_register_sink(const char *name, const char *desc,
-		const char *unique_id, ast_cdr_sink_cb sink_cb, void *data)
+struct ast_cdr_backend *__ast_cdr_register_sink(const char *name, const char *desc,
+		const char *unique_id, ast_cdr_sink_cb sink_cb, void *data,
+		struct ast_module *mod)
 {
 	union cdr_backend_cb cb = {
 		.sink_cb = sink_cb,
 	};
 
 	return cdr_backend_register(CDR_BACKEND_TYPE_SINK, cb, data,
-			name, desc, unique_id);
+			name, desc, unique_id, mod);
 }
 
 struct ast_cdr_backend *ast_cdr_unregister_sink(struct ast_cdr_backend *backend)
@@ -392,7 +400,7 @@
 	};
 
 	backend = cdr_backend_register(CDR_BACKEND_TYPE_LEGACY, cb, NULL,
-			name, desc, NULL);
+			name, desc, NULL, NULL);
 
 	if (backend) {
 		ao2_t_ref(backend, -1, "kill ref from creation, not needed");
@@ -1503,6 +1511,9 @@
 			release_cdr_wrap(backend, wrap, CDR_WRAP_CACHE);
 		}
 	}
+	if (backend->mod) {
+		ast_module_unref(backend->mod);
+	}
 	ao2_unlock(backend);
 
 	ao2_t_ref(backend, -1, "done with ref in flush_cdr_q");
@@ -1553,7 +1564,9 @@
 	}
 
 	cdr_backend_queue(backend, wrap, QUEUE_TAIL);
-
+	if (backend->mod) {
+		ast_module_ref(backend->mod);
+	}
 	ast_taskprocessor_push(backend->tps, flush_cdr_q, backend);
 }
 
@@ -1860,9 +1873,13 @@
 {
 	struct ast_cdr_backend *backend = obj;
 
+	ao2_lock(backend);
 	ao2_t_ref(backend, +1, "ref for bumping backend");
-
+	if (backend->mod) {
+		ast_module_ref(backend->mod);
+	}
 	ast_taskprocessor_push(backend->tps, flush_cdr_q, backend);
+	ao2_unlock(backend);
 
 	return 0;
 }




More information about the asterisk-commits mailing list