From 1bb58646de07501c96c53a963820ef70f73d50c5 Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Wed, 13 Aug 2003 15:25:16 +0000 Subject: Totally revamp thread debugging to support locating and removing deadlocks git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1310 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_modem.c | 64 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'channels/chan_modem.c') diff --git a/channels/chan_modem.c b/channels/chan_modem.c index 900eb0ad5..b62002679 100755 --- a/channels/chan_modem.c +++ b/channels/chan_modem.c @@ -71,14 +71,14 @@ static int baudrate = 115200; static int stripmsd = 0; -static pthread_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER; +static ast_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER; /* Protect the interface list (of ast_modem_pvt's) */ -static pthread_mutex_t iflock = AST_MUTEX_INITIALIZER; +static ast_mutex_t iflock = AST_MUTEX_INITIALIZER; /* Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. */ -static pthread_mutex_t monlock = AST_MUTEX_INITIALIZER; +static ast_mutex_t monlock = AST_MUTEX_INITIALIZER; /* This is the thread for the monitor which checks for input on the channels which are not currently in use. */ @@ -421,11 +421,11 @@ static int modem_hangup(struct ast_channel *ast) memset(p->cid, 0, sizeof(p->cid)); memset(p->dnid, 0, sizeof(p->dnid)); ((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL; - ast_pthread_mutex_lock(&usecnt_lock); + ast_mutex_lock(&usecnt_lock); usecnt--; if (usecnt < 0) ast_log(LOG_WARNING, "Usecnt < 0???\n"); - ast_pthread_mutex_unlock(&usecnt_lock); + ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name); @@ -525,9 +525,9 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state) if (strlen(i->dnid)) strncpy(tmp->exten, i->dnid, sizeof(tmp->exten) - 1); i->owner = tmp; - ast_pthread_mutex_lock(&usecnt_lock); + ast_mutex_lock(&usecnt_lock); usecnt++; - ast_pthread_mutex_unlock(&usecnt_lock); + ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); if (state != AST_STATE_DOWN) { if (ast_pbx_start(tmp)) { @@ -570,14 +570,14 @@ static void *do_monitor(void *data) for(;;) { /* Don't let anybody kill us right away. Nobody should lock the interface list and wait for the monitor list, but the other way around is okay. */ - if (ast_pthread_mutex_lock(&monlock)) { + if (ast_mutex_lock(&monlock)) { ast_log(LOG_ERROR, "Unable to grab monitor lock\n"); return NULL; } /* Lock the interface list */ - if (ast_pthread_mutex_lock(&iflock)) { + if (ast_mutex_lock(&iflock)) { ast_log(LOG_ERROR, "Unable to grab interface lock\n"); - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); return NULL; } /* Build the stuff we're going to select on, that is the socket of every @@ -600,10 +600,10 @@ static void *do_monitor(void *data) i = i->next; } /* Okay, now that we know what to do, release the interface lock */ - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); /* And from now on, we're okay to be killed, so release the monitor lock as well */ - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); #if 0 ast_log(LOG_DEBUG, "In monitor, n=%d, pid=%d\n", n, getpid()); #endif @@ -618,7 +618,7 @@ static void *do_monitor(void *data) } /* Alright, lock the interface list again, and let's look and see what has happened */ - if (ast_pthread_mutex_lock(&iflock)) { + if (ast_mutex_lock(&iflock)) { ast_log(LOG_WARNING, "Unable to lock the interface list\n"); continue; } @@ -634,7 +634,7 @@ static void *do_monitor(void *data) } i=i->next; } - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); } /* Never reached */ return NULL; @@ -646,12 +646,12 @@ static int restart_monitor() /* If we're supposed to be stopped -- stay stopped */ if (monitor_thread == -2) return 0; - if (ast_pthread_mutex_lock(&monlock)) { + if (ast_mutex_lock(&monlock)) { ast_log(LOG_WARNING, "Unable to lock monitor\n"); return -1; } if (monitor_thread == pthread_self()) { - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); ast_log(LOG_WARNING, "Cannot kill myself\n"); return -1; } @@ -663,11 +663,11 @@ static int restart_monitor() } /* Start a new monitor */ if (pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) { - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); return -1; } - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); return 0; } @@ -762,7 +762,7 @@ static struct ast_channel *modem_request(char *type, int format, void *data) } /* Search for an unowned channel */ - if (ast_pthread_mutex_lock(&iflock)) { + if (ast_mutex_lock(&iflock)) { ast_log(LOG_ERROR, "Unable to lock interface list???\n"); return NULL; } @@ -799,7 +799,7 @@ static struct ast_channel *modem_request(char *type, int format, void *data) if (!p) ast_log(LOG_WARNING, "Requested device '%s' does not exist\n", dev); - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); return tmp; } @@ -852,7 +852,7 @@ int load_module() ast_log(LOG_ERROR, "Unable to load config %s\n", config); return -1; } - if (ast_pthread_mutex_lock(&iflock)) { + if (ast_mutex_lock(&iflock)) { /* It's a little silly to lock it, but we mind as well just to be sure */ ast_log(LOG_ERROR, "Unable to lock interface list???\n"); return -1; @@ -869,7 +869,7 @@ int load_module() } else { ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); ast_destroy(cfg); - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); unload_module(); return -1; } @@ -881,7 +881,7 @@ int load_module() if (ast_load_resource(driver)) { ast_log(LOG_ERROR, "Failed to load driver %s\n", driver); ast_destroy(cfg); - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); unload_module(); return -1; } @@ -915,7 +915,7 @@ int load_module() } v = v->next; } - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); if (ast_channel_register(type, tdesc, /* XXX Don't know our types -- maybe we should register more than one XXX */ AST_FORMAT_SLINEAR, modem_request)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); @@ -934,7 +934,7 @@ int unload_module() struct ast_modem_pvt *p, *pl; /* First, take us out of the channel loop */ ast_channel_unregister(type); - if (!ast_pthread_mutex_lock(&iflock)) { + if (!ast_mutex_lock(&iflock)) { /* Hangup all interfaces if they have an owner */ p = iflist; while(p) { @@ -943,24 +943,24 @@ int unload_module() p = p->next; } iflist = NULL; - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; } - if (!ast_pthread_mutex_lock(&monlock)) { + if (!ast_mutex_lock(&monlock)) { if (monitor_thread > -1) { pthread_cancel(monitor_thread); pthread_join(monitor_thread, NULL); } monitor_thread = -2; - ast_pthread_mutex_unlock(&monlock); + ast_mutex_unlock(&monlock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; } - if (!ast_pthread_mutex_lock(&iflock)) { + if (!ast_mutex_lock(&iflock)) { /* Destroy all the interfaces and free their memory */ p = iflist; while(p) { @@ -973,7 +973,7 @@ int unload_module() free(pl); } iflist = NULL; - ast_pthread_mutex_unlock(&iflock); + ast_mutex_unlock(&iflock); } else { ast_log(LOG_WARNING, "Unable to lock the monitor\n"); return -1; @@ -985,9 +985,9 @@ int unload_module() int usecount(void) { int res; - ast_pthread_mutex_lock(&usecnt_lock); + ast_mutex_lock(&usecnt_lock); res = usecnt; - ast_pthread_mutex_unlock(&usecnt_lock); + ast_mutex_unlock(&usecnt_lock); return res; } -- cgit v1.2.3