aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-13 15:25:16 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-13 15:25:16 +0000
commitdbc9edcaac6ec1d2059f4c5bcd27cca6c266f5bf (patch)
tree3f2cc11c392b1496cf6518e8b6eb99e8b04417a1 /res
parent231b9aad4020331a8c68d1a2826ee1ef930ec57b (diff)
Totally revamp thread debugging to support locating and removing deadlocks
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1310 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rwxr-xr-xres/res_crypto.c30
-rwxr-xr-xres/res_indications.c6
-rwxr-xr-xres/res_monitor.c22
-rwxr-xr-xres/res_musiconhold.c30
-rwxr-xr-xres/res_parking.c20
5 files changed, 54 insertions, 54 deletions
diff --git a/res/res_crypto.c b/res/res_crypto.c
index 94263bea9..2a2e5cb8b 100755
--- a/res/res_crypto.c
+++ b/res/res_crypto.c
@@ -59,7 +59,7 @@
static char base64[64];
static char b2a[256];
-static pthread_mutex_t keylock = AST_MUTEX_INITIALIZER;
+static ast_mutex_t keylock = AST_MUTEX_INITIALIZER;
#define KEY_NEEDS_PASSCODE (1 << 16)
@@ -120,7 +120,7 @@ static int pw_cb(char *buf, int size, int rwflag, void *userdata)
struct ast_key *ast_key_get(char *kname, int ktype)
{
struct ast_key *key;
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key = keys;
while(key) {
if (!strcmp(kname, key->name) &&
@@ -128,7 +128,7 @@ struct ast_key *ast_key_get(char *kname, int ktype)
break;
key = key->next;
}
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
return key;
}
@@ -156,7 +156,7 @@ static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, i
/* Get actual filename */
snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key = keys;
while(key) {
/* Look for an existing version already */
@@ -164,7 +164,7 @@ static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, i
break;
key = key->next;
}
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
/* Open file */
f = fopen(ffname, "r");
@@ -213,7 +213,7 @@ static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, i
fill it with what we know */
/* Gotta lock if this one already exists */
if (found)
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
/* First the filename */
strncpy(key->fn, ffname, sizeof(key->fn));
/* Then the name */
@@ -262,12 +262,12 @@ static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, i
*not2 = 1;
}
if (found)
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
if (!found) {
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key->next = keys;
keys = key;
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
}
return key;
}
@@ -456,13 +456,13 @@ static void crypto_load(int ifd, int ofd)
struct dirent *ent;
int note = 0;
/* Mark all keys for deletion */
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key = keys;
while(key) {
key->delme = 1;
key = key->next;
}
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
/* Load new keys */
dir = opendir((char *)ast_config_AST_KEY_DIR);
if (dir) {
@@ -475,7 +475,7 @@ static void crypto_load(int ifd, int ofd)
if (note) {
ast_log(LOG_NOTICE, "Please run the command 'init keys' to enter the passcodes for the keys\n");
}
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key = keys;
last = NULL;
while(key) {
@@ -494,7 +494,7 @@ static void crypto_load(int ifd, int ofd)
last = key;
key = nkey;
}
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
}
static void md52sum(char *sum, unsigned char *md5)
@@ -509,7 +509,7 @@ static int show_keys(int fd, int argc, char *argv[])
struct ast_key *key;
char sum[16 * 2 + 1];
- ast_pthread_mutex_lock(&keylock);
+ ast_mutex_lock(&keylock);
key = keys;
ast_cli(fd, "%-18s %-8s %-16s %-33s\n", "Key Name", "Type", "Status", "Sum");
while(key) {
@@ -520,7 +520,7 @@ static int show_keys(int fd, int argc, char *argv[])
key = key->next;
}
- ast_pthread_mutex_unlock(&keylock);
+ ast_mutex_unlock(&keylock);
return RESULT_SUCCESS;
}
diff --git a/res/res_indications.c b/res/res_indications.c
index 5f039f6c7..0983efbca 100755
--- a/res/res_indications.c
+++ b/res/res_indications.c
@@ -133,7 +133,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
char buf[256];
int found_country = 0;
- if (ast_pthread_mutex_lock(&tzlock)) {
+ if (ast_mutex_lock(&tzlock)) {
ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
return 0;
}
@@ -144,7 +144,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
for (tz=tone_zones; tz; tz=tz->next) {
ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
}
- ast_pthread_mutex_unlock(&tzlock);
+ ast_mutex_unlock(&tzlock);
return 0;
}
/* there was a request for specific country(ies), lets humor them */
@@ -174,7 +174,7 @@ static int handle_show_indications(int fd, int argc, char *argv[])
}
if (!found_country)
ast_cli(fd,"No countries matched your criteria.\n");
- ast_pthread_mutex_unlock(&tzlock);
+ ast_mutex_unlock(&tzlock);
return -1;
}
diff --git a/res/res_monitor.c b/res/res_monitor.c
index f66356152..d7f73dd1f 100755
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -15,7 +15,7 @@
#define AST_MONITOR_DIR INSTALL_PREFIX "/var/spool/asterisk/monitor"
-static pthread_mutex_t monitorlock = AST_MUTEX_INITIALIZER;
+static ast_mutex_t monitorlock = AST_MUTEX_INITIALIZER;
static unsigned long seq = 0;
@@ -48,7 +48,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
int res = 0;
if( need_lock ) {
- if (ast_pthread_mutex_lock(&chan->lock)) {
+ if (ast_mutex_lock(&chan->lock)) {
ast_log(LOG_WARNING, "Unable to lock channel\n");
return -1;
}
@@ -77,13 +77,13 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
AST_MONITOR_DIR, fname_base );
*monitor->filename_base = 0;
} else {
- ast_pthread_mutex_lock( &monitorlock );
+ ast_mutex_lock( &monitorlock );
snprintf( monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
AST_MONITOR_DIR, seq );
snprintf( monitor->write_filename, FILENAME_MAX, "%s/audio-out-%ld",
AST_MONITOR_DIR, seq );
seq++;
- ast_pthread_mutex_unlock( &monitorlock );
+ ast_mutex_unlock( &monitorlock );
channel_name = strdup( chan->name );
while( ( p = strchr( channel_name, '/' ) ) ) {
@@ -113,7 +113,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
ast_log( LOG_WARNING, "Could not create file %s\n",
monitor->read_filename );
free( monitor );
- ast_pthread_mutex_unlock(&chan->lock);
+ ast_mutex_unlock(&chan->lock);
return -1;
}
if( ast_fileexists( monitor->write_filename, NULL, NULL ) > 0 ) {
@@ -126,7 +126,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
monitor->write_filename );
ast_closestream( monitor->read_stream );
free( monitor );
- ast_pthread_mutex_unlock(&chan->lock);
+ ast_mutex_unlock(&chan->lock);
return -1;
}
chan->monitor = monitor;
@@ -137,7 +137,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
}
if( need_lock ) {
- ast_pthread_mutex_unlock(&chan->lock);
+ ast_mutex_unlock(&chan->lock);
}
return res;
}
@@ -146,7 +146,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
int ast_monitor_stop( struct ast_channel *chan, int need_lock )
{
if(need_lock) {
- if(ast_pthread_mutex_lock(&chan->lock)) {
+ if(ast_mutex_lock(&chan->lock)) {
ast_log(LOG_WARNING, "Unable to lock channel\n");
return -1;
}
@@ -196,7 +196,7 @@ int ast_monitor_stop( struct ast_channel *chan, int need_lock )
}
if( need_lock ) {
- ast_pthread_mutex_unlock(&chan->lock);
+ ast_mutex_unlock(&chan->lock);
}
return 0;
}
@@ -213,7 +213,7 @@ int ast_monitor_change_fname( struct ast_channel *chan,
}
if( need_lock ) {
- if (ast_pthread_mutex_lock(&chan->lock)) {
+ if (ast_mutex_lock(&chan->lock)) {
ast_log(LOG_WARNING, "Unable to lock channel\n");
return -1;
}
@@ -230,7 +230,7 @@ int ast_monitor_change_fname( struct ast_channel *chan,
}
if( need_lock ) {
- ast_pthread_mutex_unlock(&chan->lock);
+ ast_mutex_unlock(&chan->lock);
}
return 0;
}
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index e1ae942e7..9ef8e55a3 100755
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -91,7 +91,7 @@ struct mohdata {
static struct mohclass *mohclasses;
-static pthread_mutex_t moh_lock = AST_MUTEX_INITIALIZER;
+static ast_mutex_t moh_lock = AST_MUTEX_INITIALIZER;
#define MPG_123 "/usr/bin/mpg123"
#define MAX_MP3S 256
@@ -283,7 +283,7 @@ static void *monmp3thread(void *data)
ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, res * 2);
continue;
}
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
moh = class->members;
while(moh) {
/* Write data */
@@ -292,7 +292,7 @@ static void *monmp3thread(void *data)
ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2);
moh = moh->next;
}
- pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
}
return NULL;
}
@@ -373,7 +373,7 @@ static void moh_release(struct ast_channel *chan, void *data)
{
struct mohdata *moh = data, *prev, *cur;
int oldwfmt;
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
/* Unlink */
prev = NULL;
cur = moh->parent->members;
@@ -388,7 +388,7 @@ static void moh_release(struct ast_channel *chan, void *data)
prev = cur;
cur = cur->next;
}
- ast_pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
close(moh->pipe[0]);
close(moh->pipe[1]);
oldwfmt = moh->origwfmt;
@@ -405,7 +405,7 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
{
struct mohdata *res;
struct mohclass *class;
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
class = get_mohbyname(params);
if (class)
res = mohalloc(class);
@@ -414,7 +414,7 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
ast_log(LOG_WARNING, "No class: %s\n", (char *)params);
res = NULL;
}
- ast_pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
if (res) {
res->origwfmt = chan->writeformat;
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
@@ -478,9 +478,9 @@ static int moh_register(char *classname, char *mode, char *param, char *miscargs
{
struct mohclass *moh;
int x;
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
moh = get_mohbyname(classname);
- ast_pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
if (moh) {
ast_log(LOG_WARNING, "Music on Hold '%s' already exists\n", classname);
return -1;
@@ -523,10 +523,10 @@ static int moh_register(char *classname, char *mode, char *param, char *miscargs
free(moh);
return -1;
}
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
moh->next = mohclasses;
mohclasses = moh;
- ast_pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
return 0;
}
@@ -575,17 +575,17 @@ static void ast_moh_destroy(void)
{
struct mohclass *moh;
char buff[8192];
- int bytes, tbytes, stime = 0;
+ int bytes, tbytes=0, stime = 0;
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Destroying any remaining musiconhold processes\n");
- ast_pthread_mutex_lock(&moh_lock);
+ ast_mutex_lock(&moh_lock);
moh = mohclasses;
while(moh) {
if (moh->pid) {
ast_log(LOG_DEBUG, "killing %d!\n", moh->pid);
stime = time(NULL);
kill(moh->pid, SIGABRT);
- while (bytes = read(moh->srcfd, buff, 8192) && time(NULL) < stime + 5) {
+ while ((bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime + 5) {
tbytes = tbytes + bytes;
}
ast_log(LOG_DEBUG, "mpg123 pid %d and child died after %d bytes read\n", moh->pid, tbytes);
@@ -594,7 +594,7 @@ static void ast_moh_destroy(void)
}
moh = moh->next;
}
- ast_pthread_mutex_unlock(&moh_lock);
+ ast_mutex_unlock(&moh_lock);
}
int load_module(void)
diff --git a/res/res_parking.c b/res/res_parking.c
index 821dcee79..828be881b 100755
--- a/res/res_parking.c
+++ b/res/res_parking.c
@@ -83,7 +83,7 @@ struct parkeduser {
static struct parkeduser *parkinglot;
-static pthread_mutex_t parking_lock = AST_MUTEX_INITIALIZER;
+static ast_mutex_t parking_lock = AST_MUTEX_INITIALIZER;
static pthread_t parking_thread;
@@ -109,7 +109,7 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
int x;
pu = malloc(sizeof(struct parkeduser));
if (pu) {
- ast_pthread_mutex_lock(&parking_lock);
+ ast_mutex_lock(&parking_lock);
for (x=parking_start;x<=parking_stop;x++) {
cur = parkinglot;
while(cur) {
@@ -151,7 +151,7 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
pu->priority = chan->priority;
pu->next = parkinglot;
parkinglot = pu;
- ast_pthread_mutex_unlock(&parking_lock);
+ ast_mutex_unlock(&parking_lock);
/* Wake up the (presumably select()ing) thread */
pthread_kill(parking_thread, SIGURG);
if (option_verbose > 1)
@@ -162,7 +162,7 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
} else {
ast_log(LOG_WARNING, "No more parking spaces\n");
free(pu);
- ast_pthread_mutex_unlock(&parking_lock);
+ ast_mutex_unlock(&parking_lock);
return -1;
}
} else {
@@ -412,7 +412,7 @@ static void *do_parking_thread(void *ignore)
for (;;) {
ms = -1;
max = -1;
- ast_pthread_mutex_lock(&parking_lock);
+ ast_mutex_lock(&parking_lock);
pl = NULL;
pu = parkinglot;
gettimeofday(&tv, NULL);
@@ -488,7 +488,7 @@ std: for (x=0;x<AST_MAX_FDS;x++) {
}
}
}
- ast_pthread_mutex_unlock(&parking_lock);
+ ast_mutex_unlock(&parking_lock);
rfds = nrfds;
efds = nefds;
tv.tv_sec = ms / 1000;
@@ -514,7 +514,7 @@ static int park_exec(struct ast_channel *chan, void *data)
}
LOCAL_USER_ADD(u);
park = atoi((char *)data);
- ast_pthread_mutex_lock(&parking_lock);
+ ast_mutex_lock(&parking_lock);
pu = parkinglot;
while(pu) {
if (pu->parkingnum == park) {
@@ -527,7 +527,7 @@ static int park_exec(struct ast_channel *chan, void *data)
pl = pu;
pu = pu->next;
}
- ast_pthread_mutex_unlock(&parking_lock);
+ ast_mutex_unlock(&parking_lock);
if (pu) {
peer = pu->chan;
free(pu);
@@ -578,7 +578,7 @@ static int handle_parkedcalls(int fd, int argc, char *argv[])
ast_cli(fd, "%4s %25s (%-15s %-12s %-4s) %-6s \n", "Num", "Channel"
, "Context", "Extension", "Pri", "Timeout");
- ast_pthread_mutex_lock(&parking_lock);
+ ast_mutex_lock(&parking_lock);
cur=parkinglot;
while(cur) {
@@ -589,7 +589,7 @@ static int handle_parkedcalls(int fd, int argc, char *argv[])
cur = cur->next;
}
- ast_pthread_mutex_unlock(&parking_lock);
+ ast_mutex_unlock(&parking_lock);
return RESULT_SUCCESS;
}