summaryrefslogtreecommitdiff
path: root/main/cdr.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-11-04 00:02:06 +0000
committerMatthew Jordan <mjordan@digium.com>2012-11-04 00:02:06 +0000
commit19282f682ef17ba8e4895e04492bf9f72b5655af (patch)
tree387ee1812b5fef811498a989b613980a744d8352 /main/cdr.c
parent27a9bab7069dab4f9cb87e731ffa827ffa1c4002 (diff)
Prevent multiple CDR batches from conflicting when scheduling the CDR write
The Asterisk Test Suite caught an error condition where a scheduled CDR batch write can be deleted twice if two channels attempt to post their CDRs at the same time. The batch CDR mutex is locked while the CDRs are appended to the current batch list; however, it is unlocked prior to actually scheduling the CDR write. As such, two threads can attempt to remove the currently scheduled batch write at the same time, resulting in an assertion error. This patch extends the time that the mutex is locked to encompass actually scheduling the write. This prevents two threads from unscheduling the currently scheduled write at the same time. ........ Merged revisions 375727 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 375728 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 375729 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@375730 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/cdr.c')
-rw-r--r--main/cdr.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main/cdr.c b/main/cdr.c
index 44cf1c3d2..416895de5 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1424,11 +1424,13 @@ void ast_cdr_detach(struct ast_cdr *cdr)
newtail->cdr = cdr;
batch->tail = newtail;
curr = batch->size++;
- ast_mutex_unlock(&cdr_batch_lock);
/* if we have enough stuff to post, then do it */
- if (curr >= (batchsize - 1))
+ if (curr >= (batchsize - 1)) {
submit_unscheduled_batch();
+ }
+
+ ast_mutex_unlock(&cdr_batch_lock);
}
static void *do_cdr(void *data)