[asterisk-commits] juggie: branch juggie/NoLossCDR r79085 - /team/juggie/NoLossCDR/main/cdr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 10 14:23:33 CDT 2007


Author: juggie
Date: Fri Aug 10 14:23:32 2007
New Revision: 79085

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79085
Log:
some minor changes to the threads to not hammer a down backend

Modified:
    team/juggie/NoLossCDR/main/cdr.c

Modified: team/juggie/NoLossCDR/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/juggie/NoLossCDR/main/cdr.c?view=diff&rev=79085&r1=79084&r2=79085
==============================================================================
--- team/juggie/NoLossCDR/main/cdr.c (original)
+++ team/juggie/NoLossCDR/main/cdr.c Fri Aug 10 14:23:32 2007
@@ -72,6 +72,7 @@
 	int waiting_cdrs;
 	pthread_t cdr_thread;
 	ast_cond_t cdr_pending_cond;
+	ast_cond_t cdr_retry_cond;
 	AST_LIST_HEAD(, ast_cdr) cdr_queue;
 	AST_RWLIST_ENTRY(ast_cdr_beitem) list;
 };
@@ -129,6 +130,7 @@
 	ast_copy_string(i->desc, desc, sizeof(i->desc));
 	i->be_data = be_data;
 	ast_cond_init(&i->cdr_pending_cond, NULL);
+	ast_cond_init(&i->cdr_retry_cond, NULL);
 	if (ast_pthread_create_background(&i->cdr_thread, NULL, do_cdr, i) < 0)
 		ast_log(LOG_ERROR, "Unable to start CDR thread.\n");
 	AST_RWLIST_INSERT_HEAD(&be_list, i, list);
@@ -152,6 +154,7 @@
 			pthread_join(i->cdr_thread, NULL);
 			i->cdr_thread = AST_PTHREADT_NULL;
 			ast_cond_destroy(&i->cdr_pending_cond);
+			ast_cond_destroy(&i->cdr_retry_cond);
 			AST_RWLIST_REMOVE_CURRENT(&be_list, list);
 			if (option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s - %s' CDR backend\n", name, name_detail);
@@ -798,6 +801,8 @@
 {
 	struct ast_cdr_beitem *i = data;
 	struct ast_cdr *next = NULL, *cdr = NULL;
+	struct timespec ts;
+	struct timeval tv;
 	int be_res = 0;
 
 	ast_debug(1, "CDR Worker thread for %s started\n", i->name);
@@ -828,6 +833,10 @@
 					break;
 				} else if (be_res == AST_CDR_POST_RETRY) {
 					ast_debug(1, "cdr insert into %s temporarily failed, retrying\n", i->name);
+					tv = ast_tvadd(ast_tvnow(), ast_samp2tv(30000, 1000));
+					ts.tv_sec = tv.tv_sec;
+					ts.tv_nsec = tv.tv_usec * 1000;
+					ast_cond_timedwait(&i->cdr_retry_cond, &i->cdr_queue.lock, &ts);
 				} else if (be_res == AST_CDR_POST_FATAL){
 					ast_log(LOG_ERROR, "cdr insert failed in: %s, record lost\n",i->name);
 					break;
@@ -952,10 +961,12 @@
 			i->cancel_thread = 1;
 			/* signal the thread so it can exit */
 			ast_cond_signal(&i->cdr_pending_cond);
+			ast_cond_signal(&i->cdr_retry_cond);
 			/* wait for thread to exit so we can clean up */
 			pthread_join(i->cdr_thread, NULL);
 			i->cdr_thread = AST_PTHREADT_NULL;
 			ast_cond_destroy(&i->cdr_pending_cond);
+			ast_cond_destroy(&i->cdr_retry_cond);
 			AST_RWLIST_REMOVE_CURRENT(&be_list, list);
 			ast_free(i);
 		}




More information about the asterisk-commits mailing list