From f34b684e0ea709f5fc40b8b8154e0aca62f83730 Mon Sep 17 00:00:00 2001 From: Mark Spencer <markster@digium.com> Date: Tue, 27 Apr 2004 21:18:02 +0000 Subject: [PATCH] Improve responsiveness of MGCP during a reload (bug #1488) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2785 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_mgcp.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 25ae705f56..9bb7735288 100755 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -44,6 +44,9 @@ -- enhance retransmit mechanism (RTO calc. etc.) -- embedded command support */ +/* FS: Changes + * -- fixed reload_config() / do_monitor to stay responsive during reloads + */ #include <stdio.h> #include <pthread.h> @@ -3116,6 +3119,8 @@ static int mgcpsock_read(int *id, int fd, short events, void *ignore) return 1; } +static int *mgcpsock_read_id = NULL; + static void *do_monitor(void *data) { int res; @@ -3126,7 +3131,7 @@ static void *do_monitor(void *data) /* Add an I/O event to our UDP socket */ if (mgcpsock > -1) - ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL); + mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL); /* This thread monitors all the frame relay interfaces which are not yet in use (and thus do not have a separate thread) indefinitely */ @@ -3865,22 +3870,28 @@ static int reload_config(void) cat = ast_category_browse(cfg, NULL); while(cat) { if (strcasecmp(cat, "general")) { - ast_mutex_lock(&gatelock); + ast_mutex_lock(&gatelock); g = build_gateway(cat, ast_variable_browse(cfg, cat)); if (g) { if (option_verbose > 2) { ast_verbose(VERBOSE_PREFIX_3 "Added gateway '%s'\n", g->name); - } - g->next = gateways; - gateways = g; + } + g->next = gateways; + gateways = g; + } + ast_mutex_unlock(&gatelock); + + /* FS: process queue and IO */ + if (monitor_thread == pthread_self()) { + if (sched) ast_sched_runq(sched); + if (io) ast_io_wait(io, 10); } - ast_mutex_unlock(&gatelock); } cat = ast_category_browse(cfg, cat); } - /* SC: prune deleted entries etc. */ - prune_gateways(); + /* SC: prune deleted entries etc. */ + prune_gateways(); if (ntohl(bindaddr.sin_addr.s_addr)) { memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip)); @@ -3899,6 +3910,10 @@ static int reload_config(void) ast_mutex_lock(&netlock); if (mgcpsock > -1) close(mgcpsock); + + if (mgcpsock_read_id != NULL) + mgcpsock_read_id = ast_io_remove(io, mgcpsock_read_id); + mgcpsock = socket(AF_INET, SOCK_DGRAM, 0); if (mgcpsock < 0) { ast_log(LOG_WARNING, "Unable to create MGCP socket: %s\n", strerror(errno)); -- GitLab