提交 0a5a057c authored 作者: Anthony Minessale's avatar Anthony Minessale

add inbound-reg-in-new-thread sofia param to launch a new thread to process each…

add inbound-reg-in-new-thread sofia param to launch a new thread to process each new inbound register when using heavier backends
上级 18b88710
...@@ -151,6 +151,7 @@ typedef struct sofia_dispatch_event_s { ...@@ -151,6 +151,7 @@ typedef struct sofia_dispatch_event_s {
sofia_profile_t *profile; sofia_profile_t *profile;
int save; int save;
switch_core_session_t *session; switch_core_session_t *session;
switch_memory_pool_t *pool;
} sofia_dispatch_event_t; } sofia_dispatch_event_t;
struct sofia_private { struct sofia_private {
...@@ -265,6 +266,7 @@ typedef enum { ...@@ -265,6 +266,7 @@ typedef enum {
PFLAG_OPTIONS_RESPOND_503_ON_BUSY, PFLAG_OPTIONS_RESPOND_503_ON_BUSY,
PFLAG_PRESENCE_DISABLE_EARLY, PFLAG_PRESENCE_DISABLE_EARLY,
PFLAG_CONFIRM_BLIND_TRANSFER, PFLAG_CONFIRM_BLIND_TRANSFER,
PFLAG_THREAD_PER_REG,
/* No new flags below this line */ /* No new flags below this line */
PFLAG_MAX PFLAG_MAX
} PFLAGS; } PFLAGS;
......
...@@ -1282,6 +1282,48 @@ static void our_sofia_event_callback(nua_event_t event, ...@@ -1282,6 +1282,48 @@ static void our_sofia_event_callback(nua_event_t event,
} }
} }
void *SWITCH_THREAD_FUNC sofia_msg_thread_run_once(switch_thread_t *thread, void *obj)
{
sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) obj;
switch_memory_pool_t *pool = NULL;
if (de) {
pool = de->pool;
de->pool = NULL;
sofia_process_dispatch_event(&de);
}
if (pool) {
switch_core_destroy_memory_pool(&pool);
}
return NULL;
}
void sofia_process_dispatch_event_in_thread(sofia_dispatch_event_t **dep)
{
sofia_dispatch_event_t *de = *dep;
switch_threadattr_t *thd_attr = NULL;
switch_memory_pool_t *pool;
switch_thread_t *thread;
switch_core_new_memory_pool(&pool);
*dep = NULL;
de->pool = pool;
switch_threadattr_create(&thd_attr, de->pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread,
thd_attr,
sofia_msg_thread_run_once,
de,
de->pool);
}
void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) void sofia_process_dispatch_event(sofia_dispatch_event_t **dep)
{ {
sofia_dispatch_event_t *de = *dep; sofia_dispatch_event_t *de = *dep;
...@@ -1387,6 +1429,13 @@ static void sofia_queue_message(sofia_dispatch_event_t *de) ...@@ -1387,6 +1429,13 @@ static void sofia_queue_message(sofia_dispatch_event_t *de)
return; return;
} }
if (de->profile && sofia_test_pflag(de->profile, PFLAG_THREAD_PER_REG) && de->data->e_event == nua_i_register) {
sofia_process_dispatch_event_in_thread(&de);
return;
}
again: again:
for (idx = 0; idx < mod_sofia_globals.msg_queue_len; idx++) { for (idx = 0; idx < mod_sofia_globals.msg_queue_len; idx++) {
...@@ -3251,6 +3300,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) ...@@ -3251,6 +3300,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
} else { } else {
sofia_clear_pflag(profile, PFLAG_CALLID_AS_UUID); sofia_clear_pflag(profile, PFLAG_CALLID_AS_UUID);
} }
} else if (!strcasecmp(var, "inbound-reg-in-new-thread")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_THREAD_PER_REG);
} else {
sofia_clear_pflag(profile, PFLAG_THREAD_PER_REG);
}
} else if (!strcasecmp(var, "rtp-autoflush-during-bridge")) { } else if (!strcasecmp(var, "rtp-autoflush-during-bridge")) {
if (switch_true(val)) { if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE); sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
...@@ -4102,6 +4157,12 @@ switch_status_t config_sofia(int reload, char *profile_name) ...@@ -4102,6 +4157,12 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER); sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER); sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
} }
} else if (!strcasecmp(var, "inbound-reg-in-new-thread")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_THREAD_PER_REG);
} else {
sofia_clear_pflag(profile, PFLAG_THREAD_PER_REG);
}
} else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) { } else if (!strcasecmp(var, "inbound-use-callid-as-uuid")) {
if (switch_true(val)) { if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_CALLID_AS_UUID); sofia_set_pflag(profile, PFLAG_CALLID_AS_UUID);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论