mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
Use zaptel timers to wake up processes
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1002 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
2
Makefile
2
Makefile
@@ -79,6 +79,8 @@ ifeq (${OSARCH},OpenBSD)
|
||||
CFLAGS+=-pthread
|
||||
endif
|
||||
|
||||
CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
|
||||
|
||||
LIBEDIT=editline/libedit.a
|
||||
|
||||
ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; fi)
|
||||
|
@@ -678,6 +678,8 @@ static int play_and_record(struct ast_channel *chan, char *playfile, char *recor
|
||||
for (x=0;x<fmtcnt;x++) {
|
||||
if (!others[x])
|
||||
break;
|
||||
ast_stream_rewind(others[x], 1000);
|
||||
ast_truncstream(others[x]);
|
||||
ast_closestream(others[x]);
|
||||
}
|
||||
if (outmsg) {
|
||||
@@ -705,7 +707,6 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
|
||||
FILE *txt;
|
||||
int res = 0;
|
||||
int msgnum;
|
||||
int maxmessage=0;
|
||||
char date[256];
|
||||
char dir[256];
|
||||
char fn[256];
|
||||
@@ -846,7 +847,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
|
||||
fclose(txt);
|
||||
} else
|
||||
ast_log(LOG_WARNING, "Error opening text file for output\n");
|
||||
res = play_and_record(chan, NULL, fn, maxmessage, fmt);
|
||||
res = play_and_record(chan, NULL, fn, vmmaxmessage, fmt);
|
||||
if (res > 0)
|
||||
res = 0;
|
||||
txt = fopen(txtfile, "a");
|
||||
|
35
channel.c
35
channel.c
@@ -34,6 +34,10 @@
|
||||
#include <asterisk/linkedlists.h>
|
||||
#include <asterisk/indications.h>
|
||||
#include <asterisk/monitor.h>
|
||||
#ifdef ZAPTEL_OPTIMIZATIONS
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/zaptel.h>
|
||||
#endif
|
||||
|
||||
|
||||
static int shutting_down = 0;
|
||||
@@ -296,8 +300,15 @@ struct ast_channel *ast_channel_alloc(int needqueue)
|
||||
fcntl(pvt->alertpipe[1], F_SETFL, flags | O_NONBLOCK);
|
||||
} else
|
||||
pvt->alertpipe[0] = pvt->alertpipe[1] = -1;
|
||||
#ifdef ZAPTEL_OPTIMIZATIONS
|
||||
tmp->timingfd = open("/dev/zap/timer", O_RDWR);
|
||||
#else
|
||||
tmp->timingfd = -1;
|
||||
#endif
|
||||
/* Always watch the alertpipe */
|
||||
tmp->fds[AST_MAX_FDS-1] = pvt->alertpipe[0];
|
||||
/* And timing pipe */
|
||||
tmp->fds[AST_MAX_FDS-2] = tmp->timingfd;
|
||||
strncpy(tmp->name, "**Unknown**", sizeof(tmp->name)-1);
|
||||
tmp->pvt = pvt;
|
||||
/* Initial state */
|
||||
@@ -921,6 +932,17 @@ char ast_waitfordigit(struct ast_channel *c, int ms)
|
||||
return result;
|
||||
}
|
||||
|
||||
int ast_settimeout(struct ast_channel *c, int ms)
|
||||
{
|
||||
int res = -1;
|
||||
#ifdef ZAPTEL_OPTIMIZATIONS
|
||||
if (c->timingfd > -1) {
|
||||
ms *= 8;
|
||||
res = ioctl(c->timingfd, ZT_TIMERCONFIG, &ms);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
char ast_waitfordigit_full(struct ast_channel *c, int ms, int audio, int ctrl)
|
||||
{
|
||||
struct ast_frame *f;
|
||||
@@ -994,7 +1016,18 @@ struct ast_frame *ast_read(struct ast_channel *chan)
|
||||
if (chan->pvt->alertpipe[0] > -1) {
|
||||
read(chan->pvt->alertpipe[0], &blah, sizeof(blah));
|
||||
}
|
||||
|
||||
#ifdef ZAPTEL_OPTIMIZATIONS
|
||||
if ((chan->timingfd > -1) && (chan->fdno == AST_MAX_FDS - 2) && chan->exception) {
|
||||
chan->exception = 0;
|
||||
blah = -1;
|
||||
ioctl(chan->timingfd, ZT_TIMERACK, &blah);
|
||||
blah = 0;
|
||||
ioctl(chan->timingfd, ZT_TIMERCONFIG, &blah);
|
||||
f = &null_frame;
|
||||
pthread_mutex_unlock(&chan->lock);
|
||||
return f;
|
||||
}
|
||||
#endif
|
||||
/* Check for pending read queue */
|
||||
if (chan->pvt->readq) {
|
||||
f = chan->pvt->readq;
|
||||
|
@@ -3452,13 +3452,13 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
|
||||
struct iax2_peer *peer;
|
||||
int processed = 0;
|
||||
int totalcalls = 0;
|
||||
int x = -1;
|
||||
int x = 1;
|
||||
if (iaxtrunkdebug)
|
||||
ast_verbose("Beginning trunk processing\n");
|
||||
if (events & AST_IO_PRI) {
|
||||
#ifdef ZT_TIMERACK
|
||||
/* Great, this is a timing interface, just call the ioctl */
|
||||
if (ioctl(fd, ZT_TIMERACK, x))
|
||||
if (ioctl(fd, ZT_TIMERACK, &x))
|
||||
ast_log(LOG_WARNING, "Unable to acknowledge zap timer\n");
|
||||
res = 0;
|
||||
#endif
|
||||
|
15
file.c
15
file.c
@@ -615,12 +615,13 @@ char ast_waitstream(struct ast_channel *c, char *breakon)
|
||||
ast_closestream(c->stream);
|
||||
break;
|
||||
}
|
||||
/* Setup timeout if supported */
|
||||
ast_settimeout(c, res);
|
||||
res = ast_waitfor(c, res);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
|
||||
return res;
|
||||
} else
|
||||
if (res > 0) {
|
||||
} else if (res > 0) {
|
||||
fr = ast_read(c);
|
||||
if (!fr) {
|
||||
#if 0
|
||||
@@ -652,8 +653,8 @@ char ast_waitstream(struct ast_channel *c, char *breakon)
|
||||
}
|
||||
/* Ignore */
|
||||
ast_frfree(fr);
|
||||
} else
|
||||
ast_sched_runq(c->sched);
|
||||
}
|
||||
ast_sched_runq(c->sched);
|
||||
|
||||
|
||||
}
|
||||
@@ -670,6 +671,7 @@ char ast_waitstream_fr(struct ast_channel *c, char *breakon, char *forward, char
|
||||
ast_closestream(c->stream);
|
||||
break;
|
||||
}
|
||||
ast_settimeout(c, res);
|
||||
res = ast_waitfor(c, res);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
|
||||
@@ -733,6 +735,7 @@ char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int
|
||||
ast_closestream(c->stream);
|
||||
break;
|
||||
}
|
||||
ast_settimeout(c, ms);
|
||||
rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
|
||||
if (!rchan && (outfd < 0) && (ms)) {
|
||||
ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
|
||||
@@ -776,8 +779,8 @@ char ast_waitstream_full(struct ast_channel *c, char *breakon, int audiofd, int
|
||||
}
|
||||
/* Ignore */
|
||||
ast_frfree(fr);
|
||||
} else
|
||||
ast_sched_runq(c->sched);
|
||||
}
|
||||
ast_sched_runq(c->sched);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -112,6 +112,9 @@ struct ast_channel {
|
||||
struct ast_filestream *stream;
|
||||
/*! Original writer format */
|
||||
int oldwriteformat;
|
||||
|
||||
/*! Timing fd */
|
||||
int timingfd;
|
||||
|
||||
|
||||
/*! State of line -- Don't write directly, use ast_setstate */
|
||||
@@ -669,6 +672,10 @@ int ast_autoservice_start(struct ast_channel *chan);
|
||||
/*! Stop servicing a channel for us... Returns -1 on error or if channel has been hungup */
|
||||
int ast_autoservice_stop(struct ast_channel *chan);
|
||||
|
||||
/* If built with zaptel optimizations, force a scheduled expiration on the
|
||||
timer fd */
|
||||
int ast_settimeout(struct ast_channel *c, int ms);
|
||||
|
||||
/* Misc. functions below */
|
||||
|
||||
//! Waits for activity on a group of channels
|
||||
|
Reference in New Issue
Block a user