[svn-commits] kpfleming: trunk r45634 - in /trunk: channels/ include/asterisk/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Oct 18 19:16:34 MST 2006


Author: kpfleming
Date: Wed Oct 18 21:16:34 2006
New Revision: 45634

URL: http://svn.digium.com/view/asterisk?rev=45634&view=rev
Log:
restore freeing of threadstorage objects without custom cleanup functions
allow custom threadstorage init functions to return failure
use a custom init function for chan_sip's temp_pvt, to improve performance a bit

Modified:
    trunk/channels/chan_sip.c
    trunk/include/asterisk/threadstorage.h

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Oct 18 21:16:34 2006
@@ -1142,10 +1142,11 @@
 	int recheck;
 } regl;
 
+static int temp_pvt_init(void *);
 static void temp_pvt_cleanup(void *);
 
 /*! \brief A per-thread temporary pvt structure */
-AST_THREADSTORAGE_CUSTOM(ts_temp_pvt, NULL, temp_pvt_cleanup);
+AST_THREADSTORAGE_CUSTOM(ts_temp_pvt, temp_pvt_init, temp_pvt_cleanup);
 
 /*! \todo Move the sip_auth list to AST_LIST */
 static struct sip_auth *authl = NULL;		/*!< Authentication list for realm authentication */
@@ -5532,6 +5533,14 @@
 	return send_response(p, &resp, reliable, seqno);
 }
 
+static int temp_pvt_init(void *data)
+{
+	struct sip_pvt *p = data;
+
+	ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
+	return ast_string_field_init(p, 512);
+}
+
 static void temp_pvt_cleanup(void *data)
 {
 	struct sip_pvt *p = data;
@@ -5549,13 +5558,6 @@
 	if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) {
 		ast_log(LOG_NOTICE, "Failed to get temporary pvt\n");
 		return -1;
-	}
-
-	/* if the structure was just allocated, initialize it */
-	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
-		ast_set_flag(&p->flags[0], SIP_NO_HISTORY);
-		if (ast_string_field_init(p, 512))
-			return -1;
 	}
 
 	/* Initialize the bare minimum */

Modified: trunk/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/threadstorage.h?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- trunk/include/asterisk/threadstorage.h (original)
+++ trunk/include/asterisk/threadstorage.h Wed Oct 18 21:16:34 2006
@@ -42,7 +42,7 @@
 	/*! The function that initializes the key */
 	void (*key_init)(void);
 	/*! Custom initialization function specific to the object */
-	void (*custom_init)(void *);
+	int (*custom_init)(void *);
 };
 
 /*!
@@ -58,13 +58,13 @@
  * \endcode
  */
 #define AST_THREADSTORAGE(name) \
-	AST_THREADSTORAGE_CUSTOM(name, NULL, NULL) 
+	AST_THREADSTORAGE_CUSTOM(name, NULL, ast_free) 
 
 /*!
  * \brief Define a thread storage variable, with custom initialization and cleanup
  *
  * \arg name The name of the thread storage object
- * \arg init This is a custom that will be called after each thread specific
+ * \arg init This is a custom function that will be called after each thread specific
  *           object is allocated, with the allocated block of memory passed
  *           as the argument.
  * \arg cleanup This is a custom function that will be called instead of ast_free
@@ -127,8 +127,10 @@
 	if (!(buf = pthread_getspecific(ts->key))) {
 		if (!(buf = ast_calloc(1, init_size)))
 			return NULL;
-		if (ts->custom_init)
-			ts->custom_init(buf);
+		if (ts->custom_init && ts->custom_init(buf)) {
+			free(buf);
+			return NULL;
+		}
 		pthread_setspecific(ts->key, buf);
 	}
 



More information about the svn-commits mailing list