aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-22 16:02:56 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-04-22 16:02:56 +0000
commiteaae3eb4637f017ebce9acc2f04884eced04b199 (patch)
tree627970d15ce64bae5092dcc7636f4ed903658f4e /channels
parent3af23d948d272ed6a8352d5a187a1ce7da63680f (diff)
Fix swap_subs for better locking
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2746 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-xchannels/chan_zap.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index b9c3780e3..b8de9ae88 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -618,12 +618,29 @@ static int zt_get_index(struct ast_channel *ast, struct zt_pvt *p, int nullok)
return res;
}
+static void wakeup_sub(struct zt_pvt *p, int a)
+{
+ struct ast_frame null = { AST_FRAME_NULL, };
+ for (;;) {
+ if (p->subs[a].owner) {
+ if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
+ ast_mutex_unlock(&p->lock);
+ usleep(1);
+ ast_mutex_lock(&p->lock);
+ } else {
+ ast_queue_frame(p->subs[a].owner, &null);
+ ast_mutex_unlock(&p->subs[a].owner->lock);
+ }
+ } else
+ break;
+ }
+}
+
static void swap_subs(struct zt_pvt *p, int a, int b)
{
int tchan;
int tinthreeway;
struct ast_channel *towner;
- struct ast_frame null = { AST_FRAME_NULL, };
ast_log(LOG_DEBUG, "Swapping %d and %d\n", a, b);
@@ -639,15 +656,12 @@ static void swap_subs(struct zt_pvt *p, int a, int b)
p->subs[b].owner = towner;
p->subs[b].inthreeway = tinthreeway;
- if (p->subs[a].owner) {
+ if (p->subs[a].owner)
p->subs[a].owner->fds[0] = p->subs[a].zfd;
- ast_queue_frame(p->subs[a].owner, &null);
- }
- if (p->subs[b].owner) {
+ if (p->subs[b].owner)
p->subs[b].owner->fds[0] = p->subs[b].zfd;
- ast_queue_frame(p->subs[b].owner, &null);
- }
-
+ wakeup_sub(p, a);
+ wakeup_sub(p, b);
}
static int zt_open(char *fn)