[Freeswitch-svn] [commit] r7594 - freeswitch/trunk/src

Freeswitch SVN anthm at freeswitch.org
Mon Feb 11 20:27:50 EST 2008


Author: anthm
Date: Mon Feb 11 20:27:50 2008
New Revision: 7594

Modified:
   freeswitch/trunk/src/switch_core_memory.c

Log:
add per-pool mutexes option

Modified: freeswitch/trunk/src/switch_core_memory.c
==============================================================================
--- freeswitch/trunk/src/switch_core_memory.c	(original)
+++ freeswitch/trunk/src/switch_core_memory.c	Mon Feb 11 20:27:50 2008
@@ -35,6 +35,7 @@
 #include <switch.h>
 #include "private/switch_core_pvt.h"
 /*#define LOCK_MORE*/
+/*#define PER_POOL_LOCK 1*/
 
 static struct {
 	switch_mutex_t *mem_lock;
@@ -256,8 +257,30 @@
 	if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 		*pool = (switch_memory_pool_t *) pop;
 	} else {
+#ifdef PER_POOL_LOCK
+		apr_allocator_t *my_allocator = NULL;
+        apr_thread_mutex_t *my_mutex;
+
+		if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
+			return SWITCH_STATUS_MEMERR;
+		}
+
+		if ((apr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
+			apr_allocator_destroy(my_allocator);
+			my_allocator = NULL;
+			return SWITCH_STATUS_MEMERR;
+		}
+
+		if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_DEFAULT, *pool)) != APR_SUCCESS) {
+			return SWITCH_STATUS_MEMERR;
+		}
+
+		apr_allocator_mutex_set(my_allocator, my_mutex);
+		apr_allocator_owner_set(my_allocator, *pool);
+#else
 		apr_pool_create(pool, NULL);
 		switch_assert(*pool != NULL);
+#endif
 	}
 
 #ifdef DEBUG_ALLOC2
@@ -358,10 +381,14 @@
 				}
 				
 				pool = (switch_memory_pool_t *) pop;
+#if PER_POOL_LOCK
+				apr_pool_destroy(pool);
+#else
 				apr_pool_clear(pool);
 				if (switch_queue_trypush(memory_manager.pool_recycle_queue, pool) != SWITCH_STATUS_SUCCESS) {
 					apr_pool_destroy(pool);
 				}
+#endif
 				pool = NULL;
 				x--;
 			}
@@ -403,12 +430,35 @@
 {
 	switch_thread_t *thread;
     switch_threadattr_t *thd_attr;
-
+#ifdef PER_POOL_LOCK
+	apr_allocator_t *my_allocator = NULL;
+	apr_thread_mutex_t *my_mutex;
+#endif
 
 	memset(&memory_manager, 0, sizeof(memory_manager));
 
+#ifdef PER_POOL_LOCK
+		if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
+			abort();
+		}
+
+		if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
+			apr_allocator_destroy(my_allocator);
+			my_allocator = NULL;
+			abort();
+		}
+
+		if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_DEFAULT, memory_manager.memory_pool)) != APR_SUCCESS) {
+			abort();
+		}
+
+		apr_allocator_mutex_set(my_allocator, my_mutex);
+		apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
+#else
 	apr_pool_create(&memory_manager.memory_pool, NULL);
 	switch_assert(memory_manager.memory_pool != NULL);
+#endif
+
 	switch_mutex_init(&memory_manager.mem_lock, SWITCH_MUTEX_NESTED, memory_manager.memory_pool);
 	switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
 	switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);



More information about the Freeswitch-svn mailing list