[asterisk-commits] mmichelson: branch mmichelson/taskprocessor_memleak r378201 - in /team/mmiche...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 24 11:36:22 CST 2012


Author: mmichelson
Date: Mon Dec 24 11:36:17 2012
New Revision: 378201

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378201
Log:
API changes required for taskprocessors not to leak memory.

Upcoming commits will be to fix users of taskprocessors to
conform properly.


Modified:
    team/mmichelson/taskprocessor_memleak/include/asterisk/taskprocessor.h
    team/mmichelson/taskprocessor_memleak/main/taskprocessor.c

Modified: team/mmichelson/taskprocessor_memleak/include/asterisk/taskprocessor.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/taskprocessor_memleak/include/asterisk/taskprocessor.h?view=diff&rev=378201&r1=378200&r2=378201
==============================================================================
--- team/mmichelson/taskprocessor_memleak/include/asterisk/taskprocessor.h (original)
+++ team/mmichelson/taskprocessor_memleak/include/asterisk/taskprocessor.h Mon Dec 24 11:36:17 2012
@@ -89,12 +89,13 @@
  * \brief Push a task into the specified taskprocessor queue and signal the taskprocessor thread
  * \param tps The taskprocessor structure
  * \param task_exe The task handling function to push into the taskprocessor queue
+ * \param destroy The callback used to destroy task data
  * \param datap The data to be used by the task handling function
  * \retval 0 success
  * \retval -1 failure
  * \since 1.6.1
  */
-int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap);
+int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void (*destroy)(void *datap), void *datap);
 
 /*!
  * \brief Return the name of the taskprocessor singleton

Modified: team/mmichelson/taskprocessor_memleak/main/taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/taskprocessor_memleak/main/taskprocessor.c?view=diff&rev=378201&r1=378200&r2=378201
==============================================================================
--- team/mmichelson/taskprocessor_memleak/main/taskprocessor.c (original)
+++ team/mmichelson/taskprocessor_memleak/main/taskprocessor.c Mon Dec 24 11:36:17 2012
@@ -49,6 +49,8 @@
 struct tps_task {
 	/*! \brief The execute() task callback function pointer */
 	int (*execute)(void *datap);
+	/*! \brief The destroy() task callback function pointer */
+	void (*destroy)(void *datap);
 	/*! \brief The data pointer for the task execute() function */
 	void *datap;
 	/*! \brief AST_LIST_ENTRY overhead */
@@ -148,11 +150,12 @@
 }
 
 /* allocate resources for the task */
-static struct tps_task *tps_task_alloc(int (*task_exe)(void *datap), void *datap)
+static struct tps_task *tps_task_alloc(int (*task_exe)(void *datap), void (*destroy)(void *datap), void *datap)
 {
 	struct tps_task *t;
 	if ((t = ast_calloc(1, sizeof(*t)))) {
 		t->execute = task_exe;
+		t->destroy = destroy;
 		t->datap = datap;
 	}
 	return t;
@@ -162,6 +165,9 @@
 static void *tps_task_free(struct tps_task *task)
 {
 	if (task) {
+		if (task->destroy) {
+			task->destroy(task->datap);
+		}
 		ast_free(task);
 	}
 	return NULL;
@@ -496,7 +502,8 @@
 }
 
 /* push the task into the taskprocessor queue */	
-int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap)
+int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap),
+		void (*destroy)(void *datap), void *datap)
 {
 	struct tps_task *t;
 




More information about the asterisk-commits mailing list