]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
reduce memory usage
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 26 Feb 2009 22:30:00 +0000 (22:30 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 26 Feb 2009 22:30:00 +0000 (22:30 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12317 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_conference/mod_conference.c
src/switch_core_memory.c
src/switch_event.c
src/switch_log.c

index 44f0edc6fafe81ffb67b31f07ba9d7068f30c3d5..a12d57dbaf0edbf80340f352116bb0810e1ffdfa 100644 (file)
@@ -1846,7 +1846,7 @@ static void conference_loop_output(conference_member_t *member)
                        int to = 60;
                
                        if (ann) {
-                               member->conference->special_announce = switch_core_strdup(member->conference->pool, ann);
+                               member->conference->special_announce = switch_core_strdup(member->pool, ann);
                        }
 
                        switch_channel_set_private(channel, "_conference_autocall_list_", NULL);
@@ -2676,7 +2676,7 @@ static switch_status_t conference_say(conference_obj_t *conference, const char *
        if (!conference->sh) {
                memset(&conference->lsh, 0, sizeof(conference->lsh));
                if (switch_core_speech_open(&conference->lsh, conference->tts_engine, conference->tts_voice,
-                                                                       conference->rate, conference->interval, &flags, conference->pool) != SWITCH_STATUS_SUCCESS) {
+                                                                       conference->rate, conference->interval, &flags, NULL) != SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
                        return SWITCH_STATUS_FALSE;
                }
index 107b3732b9d43c2d7d2e185310853fa220fad757..733483b51008518d99e29ffd59cf76b9910f250a 100644 (file)
@@ -34,7 +34,7 @@
 //#define DEBUG_ALLOC
 //#define DEBUG_ALLOC2
 //#define DESTROY_POOLS
-//#define PER_POOL_LOCK
+#define PER_POOL_LOCK
 //#define INSTANTLY_DESTROY_POOLS
 
 #include <switch.h>
index f853145fec87ae582b1973ba5f62807217ba4519..79b22541efa84522855e671189919e1d4fe119f7 100644 (file)
@@ -83,8 +83,10 @@ static switch_mutex_t *EVENT_QUEUE_MUTEX = NULL;
 static switch_hash_t *CUSTOM_HASH = NULL;
 static int THREAD_COUNT = 0;
 static int SYSTEM_RUNNING = 0;
+#ifdef SWITCH_EVENT_RECYCLE
 static switch_queue_t *EVENT_RECYCLE_QUEUE = NULL;
 static switch_queue_t *EVENT_HEADER_RECYCLE_QUEUE = NULL;
+#endif
 static void launch_dispatch_threads(uint32_t max, int len, switch_memory_pool_t *pool);
 
 static char *my_dup(const char *s)
@@ -422,6 +424,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_reserve_subclass_detailed(const cha
 
 SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void)
 {
+#ifdef SWITCH_EVENT_RECYCLE
+
        void *pop;
        int size;
        size = switch_queue_size(EVENT_RECYCLE_QUEUE);
@@ -437,6 +441,10 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void)
        while (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
                free(pop);
        }
+#else
+       return;
+#endif
+
 }
 
 SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
@@ -569,8 +577,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
        switch_queue_create(&EVENT_QUEUE[0], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
        switch_queue_create(&EVENT_QUEUE[1], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
        switch_queue_create(&EVENT_QUEUE[2], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
+#ifdef SWITCH_EVENT_RECYCLE
        switch_queue_create(&EVENT_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
        switch_queue_create(&EVENT_HEADER_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
+#endif
 
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
        switch_threadattr_priority_increase(thd_attr);
@@ -595,7 +605,9 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
 SWITCH_DECLARE(switch_status_t) switch_event_create_subclass_detailed(const char *file, const char *func, int line,
                                                                                                                                          switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
 {
+#ifdef SWITCH_EVENT_RECYCLE
        void *pop;
+#endif
 
        *event = NULL;
 
@@ -603,12 +615,16 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_subclass_detailed(const char
                return SWITCH_STATUS_GENERR;
        }
 
+#ifdef SWITCH_EVENT_RECYCLE
        if (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
                *event = (switch_event_t *) pop;
        } else {
+#endif
                *event = ALLOC(sizeof(switch_event_t));
                switch_assert(*event);
+#ifdef SWITCH_EVENT_RECYCLE
        }
+#endif
 
        memset(*event, 0, sizeof(switch_event_t));
 
@@ -686,9 +702,13 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header(switch_event_t *event, c
                        FREE(hp->name);
                        FREE(hp->value);
                        memset(hp, 0, sizeof(*hp));
+#ifdef SWITCH_EVENT_RECYCLE
                        if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, hp) != SWITCH_STATUS_SUCCESS) {
                                FREE(hp);
                        }
+#else
+                       FREE(hp);
+#endif
                        status = SWITCH_STATUS_SUCCESS;
                } else {
                        lp = hp;
@@ -702,14 +722,18 @@ switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack
 {
        switch_event_header_t *header;
        switch_ssize_t hlen = -1;
-       void *pop;
 
+#ifdef SWITCH_EVENT_RECYCLE
+       void *pop;
        if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
                header = (switch_event_header_t *) pop;
        } else {
+#endif
                header = ALLOC(sizeof(*header));
                switch_assert(header);
+#ifdef SWITCH_EVENT_RECYCLE
        }
+#endif
 
        memset(header, 0, sizeof(*header));
 
@@ -795,17 +819,26 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
                        hp = hp->next;
                        FREE(this->name);
                        FREE(this->value);
-                       memset(this, 0, sizeof(*this));
+#ifdef SWITCH_EVENT_RECYCLE
                        if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, this) != SWITCH_STATUS_SUCCESS) {
                                FREE(this);
                        }
+#else
+                       FREE(this);
+#endif
+
+
                }
                FREE(ep->body);
                FREE(ep->subclass_name);
-               memset(ep, 0, sizeof(*ep));
+#ifdef SWITCH_EVENT_RECYCLE
                if (switch_queue_trypush(EVENT_RECYCLE_QUEUE, ep) != SWITCH_STATUS_SUCCESS) {
                        FREE(ep);
                }
+#else
+               FREE(ep);
+#endif
+
        }
        *event = NULL;
 }
index d0b44aec38bc9de8f471c4bf1e72467115d6f907..6eec4c80ed9e3727245cd8c59d1c6284944eb77f 100644 (file)
@@ -58,7 +58,9 @@ static switch_memory_pool_t *LOG_POOL = NULL;
 static switch_log_binding_t *BINDINGS = NULL;
 static switch_mutex_t *BINDLOCK = NULL;
 static switch_queue_t *LOG_QUEUE = NULL;
+#ifdef SWITCH_LOG_RECYCLE
 static switch_queue_t *LOG_RECYCLE_QUEUE = NULL;
+#endif
 static int8_t THREAD_RUNNING = 0;
 static uint8_t MAX_LEVEL = 0;
 static int mods_loaded = 0;
@@ -226,9 +228,14 @@ static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *t, void *obj)
                switch_mutex_unlock(BINDLOCK);
 
                switch_safe_free(node->data);
+#ifdef SWITCH_LOG_RECYCLE
                if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
                        free(node);
                }
+#else
+               free(node);
+#endif
+
        }
 
        THREAD_RUNNING = 0;
@@ -347,14 +354,18 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
 
        if (do_mods && level <= MAX_LEVEL) {
                switch_log_node_t *node;
+#ifdef SWITCH_LOG_RECYCLE
                void *pop = NULL;
 
                if (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
                        node = (switch_log_node_t *) pop;
                } else {
+#endif
                        node = malloc(sizeof(*node));
                        switch_assert(node);
+#ifdef SWITCH_LOG_RECYCLE
                }
+#endif
                
                node->data = data;
                data = NULL;
@@ -368,9 +379,13 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
 
                if (switch_queue_trypush(LOG_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
                        free(node->data);
+#ifdef SWITCH_LOG_RECYCLE
                        if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
                                free(node);
                        }
+#else
+                       free(node);
+#endif
                        node = NULL;
                }
        }
@@ -395,7 +410,9 @@ SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, swit
 
 
        switch_queue_create(&LOG_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);
+#ifdef SWITCH_LOG_RECYCLE
        switch_queue_create(&LOG_RECYCLE_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);
+#endif
        switch_mutex_init(&BINDLOCK, SWITCH_MUTEX_NESTED, LOG_POOL);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
        switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL);
@@ -422,6 +439,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, swit
 
 SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void)
 {
+#ifdef SWITCH_LOG_RECYCLE
        void *pop;
        int size = switch_queue_size(LOG_RECYCLE_QUEUE);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size,
@@ -429,6 +447,10 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void)
        while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
                free(pop);
        }
+#else
+       return;
+#endif
+
 }
 
 SWITCH_DECLARE(switch_status_t) switch_log_shutdown(void)