struct local_pvt *next; /* Next entity */
} *locals = NULL;
-static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f)
+static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
{
- struct ast_channel *other, *us;
+ struct ast_channel *other;
if (isoutbound) {
- us = p->chan;
other = p->owner;
} else {
- us = p->owner;
other = p->chan;
}
if (!other)
if (pthread_mutex_trylock(&other->lock)) {
/* Failed to lock. Release main lock and try again */
ast_pthread_mutex_unlock(&p->lock);
- ast_pthread_mutex_unlock(&us->lock);
+ if (us)
+ ast_pthread_mutex_unlock(&us->lock);
/* Wait just a bit */
usleep(1);
/* Only we can destroy ourselves, so we can't disappear here */
- ast_pthread_mutex_lock(&us->lock);
+ if (us)
+ ast_pthread_mutex_lock(&us->lock);
ast_pthread_mutex_lock(&p->lock);
goto retrylock;
}
if (isoutbound) {
/* Pass along answer since somebody answered us */
struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
- res = local_queue_frame(p, isoutbound, &answer);
+ res = local_queue_frame(p, isoutbound, &answer, ast);
} else
ast_log(LOG_WARNING, "Huh? Local is being asked to answer?\n");
ast_pthread_mutex_unlock(&p->lock);
/* Just queue for delivery to the other side */
ast_pthread_mutex_lock(&p->lock);
- res = local_queue_frame(p, isoutbound, f);
+ res = local_queue_frame(p, isoutbound, f, ast);
check_bridge(p, isoutbound);
ast_pthread_mutex_unlock(&p->lock);
return res;
/* Queue up a frame representing the indication as a control frame */
ast_pthread_mutex_lock(&p->lock);
f.subclass = condition;
- res = local_queue_frame(p, isoutbound, &f);
+ res = local_queue_frame(p, isoutbound, &f, ast);
ast_pthread_mutex_unlock(&p->lock);
return res;
}
int isoutbound = IS_OUTBOUND(ast, p);
ast_pthread_mutex_lock(&p->lock);
f.subclass = digit;
- res = local_queue_frame(p, isoutbound, &f);
+ res = local_queue_frame(p, isoutbound, &f, ast);
ast_pthread_mutex_unlock(&p->lock);
return res;
}
/* Need to actually hangup since there is no PBX */
ochan = p->chan;
else
- local_queue_frame(p, isoutbound, &f);
+ local_queue_frame(p, isoutbound, &f, ast);
ast_pthread_mutex_unlock(&p->lock);
if (ochan)
ast_hangup(ochan);