]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
optimizations and disable the conditional thing till we see why it dies at 100cps...
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 15 Sep 2006 21:43:18 +0000 (21:43 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 15 Sep 2006 21:43:18 +0000 (21:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2708 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/languages/mod_spidermonkey/Makefile
src/mod/timers/mod_threadtimer/mod_threadtimer.c
src/switch_channel.c
src/switch_core.c
src/switch_utils.c

index 2dbb7e31fbac416b0214bd1e26a1361a751b46cf..250c68bdc23cb46d1863fadda0b46482e3d9b33b 100644 (file)
@@ -739,7 +739,6 @@ static switch_status_t activate_rtp(private_object_t *tech_pvt)
                                          tech_pvt->read_codec.implementation->ianacode,
                                          tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
 
-
        tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
                                                                                   tech_pvt->local_sdp_audio_port,
                                                                                   tech_pvt->remote_sdp_audio_ip,
@@ -1360,80 +1359,82 @@ static void sip_i_state(int status,
        case nua_callstate_calling:
                break;
        case nua_callstate_proceeding:
-               if (session && r_sdp) {
-                       sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
-                       sdp_session_t *sdp;
-                       uint8_t match = 0;
-
-                       if (tech_pvt->num_codecs) {
-                               if ((sdp = sdp_session(parser))) {
-                                       match = negotiate_sdp(session, sdp);
+               if (channel) {
+                       if (r_sdp) {
+                               sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+                               sdp_session_t *sdp;
+                               uint8_t match = 0;
+
+                               if (tech_pvt->num_codecs) {
+                                       if ((sdp = sdp_session(parser))) {
+                                               match = negotiate_sdp(session, sdp);
+                                       }
                                }
-                       }
 
-                       if (parser) {
-                               sdp_parser_free(parser);
-                       }
+                               if (parser) {
+                                       sdp_parser_free(parser);
+                               }
 
 
-                       if (match) {
-                               tech_choose_port(tech_pvt);
-                activate_rtp(tech_pvt);
-                               switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
-                switch_channel_pre_answer(channel);
-                               return;
+                               if (match) {
+                                       tech_choose_port(tech_pvt);
+                                       activate_rtp(tech_pvt);
+                                       switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
+                                       switch_channel_pre_answer(channel);
+                                       return;
+                               }
+                               switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+                               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+                                                       //SIPTAG_CONTACT(tech_pvt->contact), 
+                                                       TAG_END());
                        }
                }
-               if (channel) {
-                       switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
-               }
-               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-                                       //SIPTAG_CONTACT(tech_pvt->contact), 
-                                       TAG_END());
+
                break;
        case nua_callstate_completing:
                nua_ack(nh, TAG_END());
                break;
        case nua_callstate_received: 
-               if (session && r_sdp) {
-                       sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
-                       sdp_session_t *sdp;
-                       uint8_t match = 0;
+               if (channel) {
+                       if (r_sdp) {
+                               sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+                               sdp_session_t *sdp;
+                               uint8_t match = 0;
 
 
 
-                       if (tech_pvt->num_codecs) {
-                               if ((sdp = sdp_session(parser))) {
-                                       match = negotiate_sdp(session, sdp);
+                               if (tech_pvt->num_codecs) {
+                                       if ((sdp = sdp_session(parser))) {
+                                               match = negotiate_sdp(session, sdp);
+                                       }
                                }
-                       }
 
-                       if (parser) {
-                               sdp_parser_free(parser);
-                       }
+                               if (parser) {
+                                       sdp_parser_free(parser);
+                               }
 
 
-                       if (match) {
-                               switch_channel_set_variable(channel, "endpoint_disposition", "RECEIVED");
-                               switch_channel_set_state(channel, CS_INIT);
-                               switch_set_flag_locked(tech_pvt, TFLAG_READY);
-                               switch_core_session_thread_launch(session);
-                               return;
+                               if (match) {
+                                       switch_channel_set_variable(channel, "endpoint_disposition", "RECEIVED");
+                                       switch_channel_set_state(channel, CS_INIT);
+                                       switch_set_flag_locked(tech_pvt, TFLAG_READY);
+                                       switch_core_session_thread_launch(session);
+                                       return;
+                               }
+                               switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+                               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+                                                       //SIPTAG_CONTACT(tech_pvt->contact), 
+                                                       TAG_END());
                        }
                }
-               if (channel) {
-                       switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
-               }
-               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-                                       //SIPTAG_CONTACT(tech_pvt->contact), 
-                                       TAG_END());
+
                break;          
        case nua_callstate_early:
                break;
        case nua_callstate_completed:
                break;
        case nua_callstate_ready:
-               if (session) {
+               if (channel) {
                        if (r_sdp) {
                                sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
                                sdp_session_t *sdp;
@@ -1458,18 +1459,19 @@ static void sip_i_state(int status,
                                        switch_channel_answer(channel);
                                        return;
                                }
+
+                               switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+                               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+                                                       //SIPTAG_CONTACT(tech_pvt->contact), 
+                                                       TAG_END());
                        } else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
                                switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
                                switch_channel_answer(channel);
                                return;
-                       }
-               }
-               if (channel) {
-                       switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+                       } //else probably an ack
+
                }
-               nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-                                       //SIPTAG_CONTACT(tech_pvt->contact), 
-                                       TAG_END());
+
                break;
        case nua_callstate_terminating:
                break;
index e5ea8fde081104f8e331d18c5eaa8ca5860257cd..49cda61e4ce69370b4fe9186458a017c1a4095c0 100644 (file)
@@ -69,7 +69,7 @@ all:  depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
 
 depends:
        MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) mozilla.tar.gz --prefix=$(PREFIX)
-       MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX)
+       MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX) --without-libidn
        MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libetpan-0.45.tar.gz --prefix=$(PREFIX)
 
 $(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
index aa9af9a6b49684c624ffc85a99d10b14fc18e693..980402f9cbf833cb3bae9c36848ab3825eb2b82a 100644 (file)
@@ -45,31 +45,27 @@ static const char modname[] = "mod_threadtimer";
 #define MAX_ELEMENTS 1000
 
 struct timer_private {
-       uint64_t tick;
-       uint64_t reference;
-       uint32_t interval;
-       //switch_mutex_t *mutex;
-       struct timer_private *next;
+    uint32_t reference;
 };
-
 typedef struct timer_private timer_private_t;
 
-struct timer_head {
-       timer_private_t *private_info;
-       switch_mutex_t *mutex;
+struct timer_matrix {
+       uint64_t tick;
+       uint32_t count;
 };
-typedef struct timer_head timer_head_t;
+typedef struct timer_matrix timer_matrix_t;
 
-static timer_head_t *TIMER_MATRIX[MAX_ELEMENTS+1];
+static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1];
 
 #define IDLE_SPEED 100
 
+
 static inline void set_timer(void)
 {
        uint32_t index = 0, min = IDLE_SPEED;
 
        for(index = 0; index < MAX_ELEMENTS; index++) {
-               if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) {
+               if (TIMER_MATRIX[index].count) {
                        if (min > index) {
                                min = index;
                        }
@@ -83,27 +79,13 @@ static inline void set_timer(void)
 static inline switch_status_t timer_init(switch_timer_t *timer)
 {
        timer_private_t *private_info;
-       timer_head_t *head;
-
 
        if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) {
+               switch_mutex_lock(globals.mutex);
+               TIMER_MATRIX[timer->interval].count++;
+               switch_mutex_unlock(globals.mutex);
                timer->private_info = private_info;
-               if (!TIMER_MATRIX[timer->interval]) {
-                       if (!(TIMER_MATRIX[timer->interval] = switch_core_alloc(module_pool, sizeof(timer_head_t)))) {
-                               return SWITCH_STATUS_MEMERR;
-                       }
-                       switch_mutex_init(&TIMER_MATRIX[timer->interval]->mutex, SWITCH_MUTEX_NESTED, module_pool);
-               }
-
-               head = TIMER_MATRIX[timer->interval];
-
-               //switch_mutex_init(&private_info->mutex, SWITCH_MUTEX_NESTED, timer->memory_pool);
-               private_info->interval = timer->interval;
-
-               switch_mutex_lock(head->mutex);
-               private_info->next = head->private_info;
-               head->private_info = private_info;
-               switch_mutex_unlock(head->mutex);
+               private_info->reference = TIMER_MATRIX[timer->interval].tick;
                set_timer();
 
                return SWITCH_STATUS_SUCCESS;
@@ -116,9 +98,7 @@ static inline switch_status_t timer_step(switch_timer_t *timer)
 {
        timer_private_t *private_info = timer->private_info;
 
-       //switch_mutex_lock(private_info->mutex);
-       private_info->reference += private_info->interval;
-       //switch_mutex_unlock(private_info->mutex);
+       private_info->reference += timer->interval;
 
        return SWITCH_STATUS_SUCCESS;
 }
@@ -128,9 +108,8 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
 {
        timer_private_t *private_info = timer->private_info;
 
-
        timer_step(timer);
-       while (private_info->tick < private_info->reference) {
+       while (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
                switch_yield(1000);
        }
        timer->samplecount += timer->samples;
@@ -144,14 +123,12 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
        timer_private_t *private_info = timer->private_info;
        switch_status_t status;
 
-       //switch_mutex_lock(private_info->mutex);
-       if (private_info->tick < private_info->reference) {
+       if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
                status = SWITCH_STATUS_FALSE;
        } else {
-               private_info->reference += private_info->interval;
+               private_info->reference += timer->interval;
                status = SWITCH_STATUS_SUCCESS;
        }
-       //switch_mutex_unlock(private_info->mutex);
 
        return status;
 }
@@ -159,26 +136,9 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
 
 static inline switch_status_t timer_destroy(switch_timer_t *timer)
 {
-       timer_private_t *private_info = timer->private_info;
-       timer_head_t *head;
-       timer_private_t *ptr, *last = NULL;
-
-       head = TIMER_MATRIX[timer->interval];
-       assert(head != NULL);
-       assert(private_info != NULL);
-
-       switch_mutex_lock(head->mutex);
-       for(ptr = head->private_info; ptr; ptr = ptr->next) {
-               if (ptr == private_info) {
-                       if (last) {
-                               last->next = private_info->next;
-                       } else {
-                               head->private_info = private_info->next;
-                       }
-               }
-               last = ptr;
-       }
-       switch_mutex_unlock(head->mutex);
+       switch_mutex_lock(globals.mutex);
+       TIMER_MATRIX[timer->interval].count--;
+       switch_mutex_unlock(globals.mutex);
        set_timer();
        timer->private_info = NULL;
        return SWITCH_STATUS_SUCCESS;
@@ -223,7 +183,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
        switch_time_t reference = switch_time_now();
        uint32_t current_ms = 0;
-       timer_private_t *ptr;
        uint32_t x;
        
        memset(&globals, 0, sizeof(globals));
@@ -235,7 +194,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 
        while(globals.RUNNING == 1) {
                reference += globals.timer_microseconds;
-               //printf("TEST %d\n", globals.timer_microseconds);
+
                while (switch_time_now() < reference) {
                        //switch_yield((reference - now) - 1000);
                        switch_yield(globals.timer_microseconds >> 1);
@@ -251,14 +210,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
                        
                        index = (current_ms % i == 0) ? i : 0; 
 
-                       if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) {
-                               switch_mutex_lock(TIMER_MATRIX[index]->mutex);
-                               for (ptr = TIMER_MATRIX[index]->private_info; ptr; ptr = ptr->next) {
-                                       //switch_mutex_lock(ptr->mutex);
-                                       ptr->tick += ptr->interval;
-                                       //switch_mutex_unlock(ptr->mutex);
-                               }
-                               switch_mutex_unlock(TIMER_MATRIX[index]->mutex);
+                       if (TIMER_MATRIX[index].count) {
+                               TIMER_MATRIX[index].tick += index;
                        }
                }
 
index af370b6d461271b7b83fcc66f60ac840da09c121..1655863286fa1baf8c91868369ecec55d9d5e922 100644 (file)
@@ -589,10 +589,11 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
                                switch_event_fire(&event);
                        }
                }
-               
+               /*              
                if (state < CS_DONE) {
                        switch_core_session_signal_state_change(channel->session);
                }
+               */
        } else {
                switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_WARNING, "%s Invalid State Change %s -> %s\n", 
                                                  channel->name,
@@ -875,7 +876,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
                }
 
                switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
-               switch_core_session_signal_state_change(channel->session);
+               //switch_core_session_signal_state_change(channel->session);
        }
        return channel->state;
 }
index 9e8e8cd88883808a3de1dacb6c3d44123084f7f3..d91091a5bf2693f496e3b81f19f343e42104107d 100644 (file)
@@ -90,8 +90,8 @@ struct switch_core_session {
        switch_audio_resampler_t *read_resampler;
        switch_audio_resampler_t *write_resampler;
 
-       switch_mutex_t *mutex;
-       switch_thread_cond_t *cond;
+       //switch_mutex_t *mutex;
+       //switch_thread_cond_t *cond;
 
        switch_thread_rwlock_t *rwlock;
 
@@ -2489,11 +2489,13 @@ static void switch_core_standard_on_hold(switch_core_session_t *session)
 
 SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
 {
-       /* If trylock fails the signal is already awake so we need'nt bother */
+       return;
+       /* If trylock fails the signal is already awake so we needn't bother 
        if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
                switch_thread_cond_signal(session->cond);
                switch_mutex_unlock(session->mutex);
        } 
+       */
 }
 
 SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session)
@@ -2605,7 +2607,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
        driver_state_handler = endpoint_interface->state_handler;
        assert(driver_state_handler != NULL);
 
-       switch_mutex_lock(session->mutex);
+       //switch_mutex_lock(session->mutex);
 
        while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
                if (state != laststate) {
@@ -2884,17 +2886,26 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                        laststate = midstate;
                }
                
-               if (state < CS_DONE && midstate == switch_channel_get_state(session->channel)) {
-                       switch_thread_cond_wait(session->cond, session->mutex);
-               } 
+               if (state >= CS_HANGUP) {
+                       goto done;
+               }
+
+               if (midstate == switch_channel_get_state(session->channel)) {
+                       //switch_thread_cond_wait(session->cond, session->mutex);
+                       switch_yield(10000);
+               } else {
+                       switch_yield(1000);
+               }
+
        }
  done:
+       //switch_mutex_unlock(session->mutex);
 
 #ifdef CRASH_PROT
        apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
 #endif
        session->thread_running = 0;
-       switch_mutex_unlock(session->mutex);
+
 }
 
 SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session)
@@ -3140,9 +3151,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
        session->enc_read_frame.data = session->enc_read_buf;
        session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
 
-       switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
+       //switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
        switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
-       switch_thread_cond_create(&session->cond, session->pool);
+       //switch_thread_cond_create(&session->cond, session->pool);
        switch_thread_rwlock_create(&session->rwlock, session->pool);
 
        switch_mutex_lock(runtime.session_table_mutex);
index a528736b1c90681c04a26ee7e3b8ae69ac129d4b..ca5b54e08e5f778b7dcce0db30d1b0fa60872a8a 100644 (file)
@@ -204,9 +204,7 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
 {
        int nsds = 0;
 
-       if (switch_poll(poll, 1, &nsds, ms) != SWITCH_STATUS_SUCCESS) {
-               return -1;
-       }
+       switch_poll(poll, 1, &nsds, ms);
 
        return nsds;
 }