[asterisk-commits] juggie: branch juggie/NoLossCDR r84017 - in /team/juggie/NoLossCDR: cdr/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Sep 27 16:09:14 CDT 2007
Author: juggie
Date: Thu Sep 27 16:09:14 2007
New Revision: 84017
URL: http://svn.digium.com/view/asterisk?view=rev&rev=84017
Log:
fix a bad merge...
Modified:
team/juggie/NoLossCDR/cdr/cdr_manager.c
team/juggie/NoLossCDR/main/cdr.c
Modified: team/juggie/NoLossCDR/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/cdr/cdr_manager.c?view=diff&rev=84017&r1=84016&r2=84017
==============================================================================
--- team/juggie/NoLossCDR/cdr/cdr_manager.c (original)
+++ team/juggie/NoLossCDR/cdr/cdr_manager.c Thu Sep 27 16:09:14 2007
@@ -52,7 +52,7 @@
static int enablecdr = 0;
struct ast_str *customfields;
-static int manager_log(struct ast_cdr *cdr);
+static int manager_log(struct ast_cdr *cdr, void * data);
static int load_config(int reload)
{
@@ -75,7 +75,7 @@
/* Standard configuration */
ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
if (enablecdr)
- ast_cdr_unregister(name);
+ ast_cdr_unregister(name, NULL);
enablecdr = 0;
return 0;
}
@@ -111,9 +111,9 @@
ast_config_destroy(cfg);
if (enablecdr && !newenablecdr)
- ast_cdr_unregister(name);
+ ast_cdr_unregister(name, NULL);
else if (!enablecdr && newenablecdr)
- ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
+ ast_cdr_register(name, NULL, "Asterisk Manager Interface CDR Backend", manager_log, NULL, NULL);
return 1;
}
Modified: team/juggie/NoLossCDR/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/main/cdr.c?view=diff&rev=84017&r1=84016&r2=84017
==============================================================================
--- team/juggie/NoLossCDR/main/cdr.c (original)
+++ team/juggie/NoLossCDR/main/cdr.c Thu Sep 27 16:09:14 2007
@@ -74,11 +74,11 @@
pthread_t cdr_thread;
ast_cond_t cdr_pending_cond;
ast_cond_t cdr_retry_cond;
+ ast_mutex_t retry_poll_lock;
AST_LIST_HEAD(, ast_cdr) cdr_queue;
AST_RWLIST_ENTRY(ast_cdr_beitem) list;
};
-AST_MUTEX_DEFINE_STATIC(retry_poll_lock);
static AST_RWLIST_HEAD_STATIC(be_list, ast_cdr_beitem);
#define SAFE_SHUTDOWN_DEFAULT 1
@@ -785,95 +785,6 @@
cdr->disposition = AST_CDR_NULL;
}
-/*! \note Don't call without cdr_batch_lock */
-static void reset_batch(void)
-{
- batch->size = 0;
- batch->head = NULL;
- batch->tail = NULL;
-}
-
-/*! \note Don't call without cdr_batch_lock */
-static int init_batch(void)
-{
- /* This is the single meta-batch used to keep track of all CDRs during the entire life of the program */
- if (!(batch = ast_malloc(sizeof(*batch))))
- return -1;
-
- reset_batch();
-
- return 0;
-}
-
-static void *do_batch_backend_process(void *data)
-{
- struct ast_cdr_batch_item *processeditem;
- struct ast_cdr_batch_item *batchitem = data;
-
- /* Push each CDR into storage mechanism(s) and free all the memory */
- while (batchitem) {
- post_cdr(batchitem->cdr);
- ast_cdr_free(batchitem->cdr);
- processeditem = batchitem;
- batchitem = batchitem->next;
- ast_free(processeditem);
- }
-
- return NULL;
-}
-
-void ast_cdr_submit_batch(int shutdown)
-{
- struct ast_cdr_batch_item *oldbatchitems = NULL;
- pthread_t batch_post_thread = AST_PTHREADT_NULL;
-
- /* if there's no batch, or no CDRs in the batch, then there's nothing to do */
- if (!batch || !batch->head)
- return;
-
- /* move the old CDRs aside, and prepare a new CDR batch */
- ast_mutex_lock(&cdr_batch_lock);
- oldbatchitems = batch->head;
- reset_batch();
- ast_mutex_unlock(&cdr_batch_lock);
-
- /* if configured, spawn a new thread to post these CDRs,
- also try to save as much as possible if we are shutting down safely */
- if (batchscheduleronly || shutdown) {
- ast_debug(1, "CDR single-threaded batch processing begins now\n");
- do_batch_backend_process(oldbatchitems);
- } else {
- if (ast_pthread_create_detached_background(&batch_post_thread, NULL, do_batch_backend_process, oldbatchitems)) {
- ast_log(LOG_WARNING, "CDR processing thread could not detach, now trying in this thread\n");
- do_batch_backend_process(oldbatchitems);
- } else {
- ast_debug(1, "CDR multi-threaded batch processing begins now\n");
- }
- }
-}
-
-static int submit_scheduled_batch(const void *data)
-{
- ast_cdr_submit_batch(0);
- /* manually reschedule from this point in time */
- cdr_sched = ast_sched_add(sched, batchtime * 1000, submit_scheduled_batch, NULL);
- /* returning zero so the scheduler does not automatically reschedule */
- return 0;
-}
-
-static void submit_unscheduled_batch(void)
-{
- /* this is okay since we are not being called from within the scheduler */
- if (cdr_sched > -1)
- ast_sched_del(sched, cdr_sched);
- /* schedule the submission to occur ASAP (1 ms) */
- cdr_sched = ast_sched_add(sched, 1, submit_scheduled_batch, NULL);
- /* signal the do_cdr thread to wakeup early and do some work (that lazy thread ;) */
- ast_mutex_lock(&cdr_pending_lock);
- ast_cond_signal(&cdr_pending_cond);
- ast_mutex_unlock(&cdr_pending_lock);
-}
-
void ast_cdr_detach(struct ast_cdr *cdr)
{
if (!cdr)
@@ -932,9 +843,9 @@
tv = ast_tvadd(ast_tvnow(), ast_samp2tv(retrydelay * 1000, 1000));
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
- ast_mutex_lock(&retry_poll_lock);
- ast_cond_timedwait(&i->cdr_retry_cond, &retry_poll_lock, &ts);
- ast_mutex_unlock(&retry_poll_lock);
+ ast_mutex_lock(&i->retry_poll_lock);
+ ast_cond_timedwait(&i->cdr_retry_cond, &i->retry_poll_lock, &ts);
+ ast_mutex_unlock(&i->retry_poll_lock);
} else if (be_res == AST_CDR_POST_FATAL){
ast_log(LOG_ERROR, "cdr insert *PERMENANTLY* failed in: %s, record lost\n",i->name);
break;
More information about the asterisk-commits
mailing list