[asterisk-commits] russell: branch russell/frame_caching r38572 - in /team/russell/frame_caching...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jul 31 00:15:17 MST 2006


Author: russell
Date: Mon Jul 31 02:15:17 2006
New Revision: 38572

URL: http://svn.digium.com/view/asterisk?rev=38572&view=rev
Log:
Ensure that when a thread is destroyed, all of the frames currently in the
cache get free'd, instead of only the frames list head structure.

Modified:
    team/russell/frame_caching/frame.c
    team/russell/frame_caching/include/asterisk/threadstorage.h

Modified: team/russell/frame_caching/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/frame.c?rev=38572&r1=38571&r2=38572&view=diff
==============================================================================
--- team/russell/frame_caching/frame.c (original)
+++ team/russell/frame_caching/frame.c Mon Jul 31 02:15:17 2006
@@ -62,8 +62,10 @@
 static unsigned int added_to_cache = 0;
 static unsigned int removed_from_cache = 0;
 
+static void frame_cache_cleanup(void *data);
+
 /*! \brief A per-thread cache of frame headers */
-AST_THREADSTORAGE(frame_cache, frame_cache_init);
+AST_THREADSTORAGE_CUSTOM(frame_cache, frame_cache_init, frame_cache_cleanup);
 
 /*! \brief This is just so ast_frames, a list head struct for holding a list of
  *  ast_frame structures, is defined. */
@@ -303,6 +305,17 @@
 	return f;
 }
 
+static void frame_cache_cleanup(void *data)
+{
+	struct ast_frames *frames = data;
+	struct ast_frame *f;
+
+	while ((f = AST_LIST_REMOVE_HEAD(frames, frame_list)))
+		free(f);
+	
+	free(frames);
+}
+
 void ast_frfree(struct ast_frame *fr)
 {
 	switch (fr->mallocd) {

Modified: team/russell/frame_caching/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/include/asterisk/threadstorage.h?rev=38572&r1=38571&r2=38572&view=diff
==============================================================================
--- team/russell/frame_caching/include/asterisk/threadstorage.h (original)
+++ team/russell/frame_caching/include/asterisk/threadstorage.h Mon Jul 31 02:15:17 2006
@@ -58,15 +58,18 @@
  * AST_THREADSTORAGE(my_buf, my_buf_init);
  * \endcode
  */
-#define AST_THREADSTORAGE(name, name_init)         \
-static void name_init(void);                       \
-static struct ast_threadstorage name = {           \
-	.once = PTHREAD_ONCE_INIT,                 \
-	.key_init = name_init,                     \
-};                                                 \
-static void name_init(void)                        \
-{                                                  \
-	pthread_key_create(&(name).key, ast_free); \
+#define AST_THREADSTORAGE(name, name_init) \
+	AST_THREADSTORAGE_CUSTOM(name, name_init, ast_free) 
+
+#define AST_THREADSTORAGE_CUSTOM(name, name_init, cleanup)  \
+static void name_init(void);                                \
+static struct ast_threadstorage name = {                    \
+	.once = PTHREAD_ONCE_INIT,                          \
+	.key_init = name_init,                              \
+};                                                          \
+static void name_init(void)                                 \
+{                                                           \
+	pthread_key_create(&(name).key, cleanup);           \
 }
 
 /*!



More information about the asterisk-commits mailing list