[Asterisk-cvs] asterisk/apps app_rpt.c,1.20,1.21
jim at lists.digium.com
jim at lists.digium.com
Sun Aug 22 00:12:37 CDT 2004
Update of /usr/cvsroot/asterisk/apps
In directory localhost.localdomain:/tmp/cvs-serv7799
Modified Files:
app_rpt.c
Log Message:
Fixed timing race with thread creation in app_rpt.c, and added settable
delays and such in config file.
Index: app_rpt.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_rpt.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- app_rpt.c 21 Aug 2004 21:41:54 -0000 1.20
+++ app_rpt.c 22 Aug 2004 03:58:42 -0000 1.21
@@ -3,7 +3,7 @@
* Asterisk -- A telephony toolkit for Linux.
*
* Radio Repeater / Remote Base program
- * version 0.15 8/21/04
+ * version 0.16 8/21/04
*
* See http://www.zapatatelephony.org/app_rpt.html
*
@@ -137,7 +137,7 @@
#include <tonezone.h>
#include <linux/zaptel.h>
-static char *tdesc = "Radio Repeater / Remote Base version 0.15 08/21/2004";
+static char *tdesc = "Radio Repeater / Remote Base version 0.16 08/21/2004";
static char *app = "Rpt";
static char *synopsis = "Radio Repeater/Remote Base Control System";
@@ -2773,6 +2773,7 @@
{
fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->rxchanname);
ast_mutex_unlock(&myrpt->lock);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
*tele++ = 0;
@@ -2784,6 +2785,7 @@
fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
ast_mutex_unlock(&myrpt->lock);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
@@ -2799,6 +2801,7 @@
{
ast_mutex_unlock(&myrpt->lock);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
}
@@ -2806,6 +2809,7 @@
{
fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
ast_mutex_unlock(&myrpt->lock);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
if (myrpt->txchanname)
@@ -2816,6 +2820,7 @@
{
fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->txchanname);
ast_mutex_unlock(&myrpt->lock);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
*tele++ = 0;
@@ -2828,6 +2833,7 @@
ast_mutex_unlock(&myrpt->lock);
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
@@ -2844,6 +2850,7 @@
ast_mutex_unlock(&myrpt->lock);
ast_hangup(myrpt->rxchannel);
ast_hangup(myrpt->txchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
}
@@ -2852,6 +2859,7 @@
fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
ast_mutex_unlock(&myrpt->lock);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
}
@@ -2868,6 +2876,7 @@
if (myrpt->txchannel != myrpt->rxchannel)
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
/* make a conference for the tx */
@@ -2883,6 +2892,7 @@
if (myrpt->txchannel != myrpt->rxchannel)
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
/* save tx conference number */
@@ -2900,6 +2910,7 @@
if (myrpt->txchannel != myrpt->rxchannel)
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
/* save pseudo channel conference number */
@@ -2914,6 +2925,7 @@
if (myrpt->txchannel != myrpt->rxchannel)
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
/* make a conference for the tx */
@@ -2930,6 +2942,7 @@
if (myrpt->txchannel != myrpt->rxchannel)
ast_hangup(myrpt->txchannel);
ast_hangup(myrpt->rxchannel);
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
}
/* Now, the idea here is to copy from the physical rx channel buffer
@@ -3531,6 +3544,7 @@
}
ast_mutex_unlock(&myrpt->lock);
if (debug) printf("@@@@ rpt:Hung up channel\n");
+ myrpt->rpt_thread = AST_PTHREADT_STOP;
pthread_exit(NULL);
return NULL;
}
@@ -3673,7 +3687,9 @@
ast_log(LOG_WARNING,"Did not specify ident for node %s\n",rpt_vars[i].name);
pthread_exit(NULL);
}
- ast_pthread_create(&rpt_vars[i].rpt_thread,NULL,rpt,(void *) &rpt_vars[i]);
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]);
}
usleep(500000);
for(;;)
@@ -3681,8 +3697,13 @@
/* Now monitor each thread, and restart it if necessary */
for(i = 0; i < n; i++)
{
+ int rv;
if (rpt_vars[i].remote) continue;
- if (pthread_kill(rpt_vars[i].rpt_thread,0))
+ if (rpt_vars[i].rpt_thread == AST_PTHREADT_STOP)
+ rv = -1;
+ else
+ rv = pthread_kill(rpt_vars[i].rpt_thread,0);
+ if (rv)
{
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
More information about the svn-commits
mailing list