[asterisk-commits] moy: branch moy/mfcr2-1.4 r218149 - /team/moy/mfcr2-1.4/channels/chan_dahdi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Sep 12 12:30:21 CDT 2009
Author: moy
Date: Sat Sep 12 12:30:14 2009
New Revision: 218149
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=218149
Log:
get rid of the monitor count to make the monitor thread sleep, now we just poll for work in the monitor thread
Modified:
team/moy/mfcr2-1.4/channels/chan_dahdi.c
Modified: team/moy/mfcr2-1.4/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/moy/mfcr2-1.4/channels/chan_dahdi.c?view=diff&rev=218149&r1=218148&r2=218149
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_dahdi.c Sat Sep 12 12:30:14 2009
@@ -309,9 +309,6 @@
openr2_context_t *protocol_context; /*!< OpenR2 context handle */
struct dahdi_pvt *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
int numchans; /*!< Number of channels in this R2 block */
- int monitored_count; /*!< Number of channels being monitored */
- ast_mutex_t monitored_count_lock; /*!< lock access to the counter */
- ast_cond_t do_monitor; /*!< Condition to wake up the monitor thread when there's work to do */
};
static struct dahdi_mfcr2 r2links[NUM_SPANS];
@@ -1375,24 +1372,6 @@
ast_mutex_unlock(&p->lock);
}
-static void dahdi_r2_update_monitor_count(struct dahdi_mfcr2 *mfcr2, int increment)
-{
- ast_mutex_lock(&mfcr2->monitored_count_lock);
- if (increment) {
- mfcr2->monitored_count++;
- if (mfcr2->monitored_count == 1) {
- ast_log(LOG_DEBUG, "At least one device needs monitoring, let's wake up that lazy bastard.\n");
- ast_cond_signal(&mfcr2->do_monitor);
- }
- } else {
- mfcr2->monitored_count--;
- if (mfcr2->monitored_count < 0) {
- ast_log(LOG_ERROR, "wtf? we have a bug here!.\n");
- }
- }
- ast_mutex_unlock(&mfcr2->monitored_count_lock);
-}
-
static void dahdi_r2_disconnect_call(struct dahdi_pvt *p, openr2_call_disconnect_cause_t cause)
{
if (openr2_chan_disconnect_call(p->r2chan, cause)) {
@@ -1441,14 +1420,12 @@
/* if the user does not want to accept on offer, then we should launch the PBX thread now */
if (!p->mfcr2_accept_on_offer) {
c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, 0);
- if (c) {
- dahdi_r2_update_monitor_count(p->mfcr2, 0);
- /* Don't disable reading since we still need to generate MF tone to accept
- the call or reject it and detect the tone off condition of the other end */
- } else {
+ if (!c) {
ast_log(LOG_ERROR, "Unable to create PBX channel on chan %d\n", p->channel);
dahdi_r2_disconnect_call(p, OR2_CAUSE_OUT_OF_ORDER);
}
+ /* Don't disable reading since we still need to generate MF tone to accept
+ the call or reject it and detect the tone off condition of the other end */
} else if (p->mfcr2_charge_calls) {
ast_log(LOG_DEBUG, "Accepting MFC/R2 call on offer with charge on chan %d\n", p->channel);
openr2_chan_accept_call(r2chan, OR2_CALL_WITH_CHARGE);
@@ -1490,7 +1467,6 @@
}
c = dahdi_new(p, AST_STATE_RING, 1, SUB_REAL, DAHDI_LAW_ALAW, 0);
if (c) {
- dahdi_r2_update_monitor_count(p->mfcr2, 0);
/* chan_dahdi will take care of reading from now on, tell the library to forget about it */
openr2_chan_disable_read(r2chan);
} else {
@@ -3761,11 +3737,9 @@
: dahdi_ast_cause_to_r2_cause(ast->hangupcause);
dahdi_r2_disconnect_call(p, r2cause);
}
- dahdi_r2_update_monitor_count(p->mfcr2, 1);
} else if (p->mfcr2call) {
ast_log(LOG_DEBUG, "Clearing call request on channel %d\n", p->channel);
p->mfcr2call = 0;
- dahdi_r2_update_monitor_count(p->mfcr2, 1);
}
#endif
#ifdef HAVE_PRI
@@ -8745,9 +8719,6 @@
ast_log(LOG_ERROR, "Failed to configure r2context from advanced configuration file %s\n", mfcr2_cur_r2proto_file);
}
}
- ast_cond_init(&dahdi_r2->do_monitor, NULL);
- ast_mutex_init(&dahdi_r2->monitored_count_lock);
- dahdi_r2->monitored_count = 0;
}
if (dahdi_r2) {
/* TODO: should we check numchans overflow, or is it already done by DAHDI? */
@@ -8777,7 +8748,6 @@
tmp->mfcr2_dnis_index = 0;
tmp->mfcr2_allow_collect_calls = mfcr2_cur_allow_collect_calls;
tmp->mfcr2_forced_release = mfcr2_cur_forced_release;
- dahdi_r2->monitored_count++;
}
}
#endif
@@ -9408,7 +9378,6 @@
}
p->mfcr2call = 1;
ast_mutex_unlock(&p->lock);
- dahdi_r2_update_monitor_count(p->mfcr2, 0);
}
#endif
if (p->channel == CHAN_PSEUDO) {
@@ -9497,10 +9466,12 @@
could be cancelled at any time and is not
using thread keys, why?, */
struct pollfd pollers[sizeof(mfcr2->pvts)];
- int nextms = 0;
+ int maxsleep = 20;
int res = 0;
int i = 0;
+ int pollsize = 0;
int oldstate = 0;
+ int was_idle = 0;
int quit_loop = 0;
/* now that we're ready to get calls, unblock our side and
get current line state */
@@ -9519,14 +9490,7 @@
while(1) {
/* we trust here that the mfcr2 channel list will not ever change once
the module is loaded */
- nextms = openr2_context_get_time_to_next_event(mfcr2->protocol_context);
- ast_mutex_lock(&mfcr2->monitored_count_lock);
- if (mfcr2->monitored_count == 0) {
- ast_log(LOG_DEBUG, "No one requires my monitoring services :-(\n");
- ast_cond_wait(&mfcr2->do_monitor, &mfcr2->monitored_count_lock);
- ast_log(LOG_DEBUG, "Alright, back to work!\n");
- }
-
+ pollsize = 0;
for (i = 0; i < mfcr2->numchans; i++) {
pollers[i].revents = 0;
pollers[i].events = 0;
@@ -9541,15 +9505,26 @@
openr2_chan_enable_read(mfcr2->pvts[i]->r2chan);
pollers[i].events = POLLIN | POLLPRI;
pollers[i].fd = mfcr2->pvts[i]->subs[SUB_REAL].dfd;
- }
- ast_mutex_unlock(&mfcr2->monitored_count_lock);
+ pollsize++;
+ }
if (quit_loop) {
break;
}
+
+ if (pollsize == 0) {
+ if (!was_idle) {
+ ast_log(LOG_NOTICE, "Monitor thread going idle since everybody has an owner\n");
+ was_idle = 1;
+ }
+ poll(NULL, 0, maxsleep);
+ continue;
+ }
+ was_idle = 0;
+
/* probably poll() is a valid cancel point, lets just be on the safe side
by calling pthread_testcancel */
pthread_testcancel();
- res = poll(pollers, mfcr2->numchans, nextms);
+ res = poll(pollers, pollsize, maxsleep);
pthread_testcancel();
if ((res < 0) && (errno != EINTR)) {
ast_log(LOG_ERROR, "going out, poll failed: %s\n", strerror(errno));
More information about the asterisk-commits
mailing list