summaryrefslogtreecommitdiff
path: root/channels/chan_dahdi.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2015-08-12 13:37:32 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2015-08-12 13:37:33 -0500
commit58edd2dddce76ead5214994a3bc0a42fd90a25cd (patch)
treecd4df8f8153b3ce7c0d4a43dc60e4e8994e0e7a8 /channels/chan_dahdi.c
parent318b97fd1e1a19fb3a03b3e7934ced74321adfb8 (diff)
parentb9b957d4e921a78b0918b584cb6e3d9a34abc160 (diff)
Merge "chan_dahdi.c: Lock private struct for ast_write()."
Diffstat (limited to 'channels/chan_dahdi.c')
-rw-r--r--channels/chan_dahdi.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index ac159527b..c17e4f891 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -8784,39 +8784,52 @@ static int my_dahdi_write(struct dahdi_pvt *p, unsigned char *buf, int len, int
static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame)
{
- struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+ struct dahdi_pvt *p;
int res;
int idx;
+
+ /* Write a frame of (presumably voice) data */
+ if (frame->frametype != AST_FRAME_VOICE) {
+ if (frame->frametype != AST_FRAME_IMAGE) {
+ ast_log(LOG_WARNING, "Don't know what to do with frame type '%u'\n",
+ frame->frametype);
+ }
+ return 0;
+ }
+
+ /* Return if it's not valid data */
+ if (!frame->data.ptr || !frame->datalen) {
+ return 0;
+ }
+
+ p = ast_channel_tech_pvt(ast);
+ ast_mutex_lock(&p->lock);
+
idx = dahdi_get_index(ast, p, 0);
if (idx < 0) {
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_WARNING, "%s doesn't really exist?\n", ast_channel_name(ast));
return -1;
}
- /* Write a frame of (presumably voice) data */
- if (frame->frametype != AST_FRAME_VOICE) {
- if (frame->frametype != AST_FRAME_IMAGE)
- ast_log(LOG_WARNING, "Don't know what to do with frame type '%u'\n", frame->frametype);
- return 0;
- }
if (p->dialing) {
+ ast_mutex_unlock(&p->lock);
ast_debug(5, "Dropping frame since I'm still dialing on %s...\n",
ast_channel_name(ast));
return 0;
}
if (!p->owner) {
+ ast_mutex_unlock(&p->lock);
ast_debug(5, "Dropping frame since there is no active owner on %s...\n",
ast_channel_name(ast));
return 0;
}
if (p->cidspill) {
+ ast_mutex_unlock(&p->lock);
ast_debug(5, "Dropping frame since I've still got a callerid spill on %s...\n",
ast_channel_name(ast));
return 0;
}
- /* Return if it's not valid data */
- if (!frame->data.ptr || !frame->datalen)
- return 0;
if (ast_format_cmp(frame->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) {
if (!p->subs[idx].linear) {
@@ -8837,10 +8850,12 @@ static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame)
}
res = my_dahdi_write(p, (unsigned char *)frame->data.ptr, frame->datalen, idx, 0);
} else {
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_WARNING, "Cannot handle frames in %s format\n",
ast_format_get_name(frame->subclass.format));
return -1;
}
+ ast_mutex_unlock(&p->lock);
if (res < 0) {
ast_log(LOG_WARNING, "write failed: %s\n", strerror(errno));
return -1;