[asterisk-commits] file: trunk r69705 - in /trunk/main: asterisk.c cdr.c dnsmgr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 18 11:37:14 CDT 2007


Author: file
Date: Mon Jun 18 11:37:14 2007
New Revision: 69705

URL: http://svn.digium.com/view/asterisk?view=rev&rev=69705
Log:
Few more rwlist conversions... why not.

Modified:
    trunk/main/asterisk.c
    trunk/main/cdr.c
    trunk/main/dnsmgr.c

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=69705&r1=69704&r2=69705
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Mon Jun 18 11:37:14 2007
@@ -188,10 +188,10 @@
 
 struct ast_atexit {
 	void (*func)(void);
-	AST_LIST_ENTRY(ast_atexit) list;
+	AST_RWLIST_ENTRY(ast_atexit) list;
 };
 
-static AST_LIST_HEAD_STATIC(atexits, ast_atexit);
+static AST_RWLIST_HEAD_STATIC(atexits, ast_atexit);
 
 time_t ast_startuptime;
 time_t ast_lastreloadtime;
@@ -252,12 +252,12 @@
 
 #if !defined(LOW_MEMORY)
 struct file_version {
-	AST_LIST_ENTRY(file_version) list;
+	AST_RWLIST_ENTRY(file_version) list;
 	const char *file;
 	char *version;
 };
 
-static AST_LIST_HEAD_STATIC(file_versions, file_version);
+static AST_RWLIST_HEAD_STATIC(file_versions, file_version);
 
 void ast_register_file_version(const char *file, const char *version)
 {
@@ -275,36 +275,36 @@
 	new->file = file;
 	new->version = (char *) new + sizeof(*new);
 	memcpy(new->version, work, version_length);
-	AST_LIST_LOCK(&file_versions);
-	AST_LIST_INSERT_HEAD(&file_versions, new, list);
-	AST_LIST_UNLOCK(&file_versions);
+	AST_RWLIST_WRLOCK(&file_versions);
+	AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
+	AST_RWLIST_UNLOCK(&file_versions);
 }
 
 void ast_unregister_file_version(const char *file)
 {
 	struct file_version *find;
 
-	AST_LIST_LOCK(&file_versions);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
+	AST_RWLIST_WRLOCK(&file_versions);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
 		if (!strcasecmp(find->file, file)) {
-			AST_LIST_REMOVE_CURRENT(&file_versions, list);
+			AST_RWLIST_REMOVE_CURRENT(&file_versions, list);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&file_versions);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&file_versions);
 
 	if (find)
 		ast_free(find);
 }
 
 struct thread_list_t {
-	AST_LIST_ENTRY(thread_list_t) list;
+	AST_RWLIST_ENTRY(thread_list_t) list;
 	char *name;
 	pthread_t id;
 };
 
-static AST_LIST_HEAD_STATIC(thread_list, thread_list_t);
+static AST_RWLIST_HEAD_STATIC(thread_list, thread_list_t);
 
 static const char show_threads_help[] =
 "Usage: core show threads\n"
@@ -318,24 +318,24 @@
 		return;
 	new->id = pthread_self();
 	new->name = name; /* steal the allocated memory for the thread name */
-	AST_LIST_LOCK(&thread_list);
-	AST_LIST_INSERT_HEAD(&thread_list, new, list);
-	AST_LIST_UNLOCK(&thread_list);
+	AST_RWLIST_WRLOCK(&thread_list);
+	AST_RWLIST_INSERT_HEAD(&thread_list, new, list);
+	AST_RWLIST_UNLOCK(&thread_list);
 }
 
 void ast_unregister_thread(void *id)
 {
 	struct thread_list_t *x;
 
-	AST_LIST_LOCK(&thread_list);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
+	AST_RWLIST_WRLOCK(&thread_list);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
 		if ((void *) x->id == id) {
-			AST_LIST_REMOVE_CURRENT(&thread_list, list);
+			AST_RWLIST_REMOVE_CURRENT(&thread_list, list);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&thread_list);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&thread_list);
 	if (x) {
 		ast_free(x->name);
 		ast_free(x);
@@ -408,12 +408,12 @@
 	int count = 0;
 	struct thread_list_t *cur;
 
-	AST_LIST_LOCK(&thread_list);
-	AST_LIST_TRAVERSE(&thread_list, cur, list) {
+	AST_RWLIST_RDLOCK(&thread_list);
+	AST_RWLIST_TRAVERSE(&thread_list, cur, list) {
 		ast_cli(fd, "%p %s\n", (void *)cur->id, cur->name);
 		count++;
 	}
-        AST_LIST_UNLOCK(&thread_list);
+        AST_RWLIST_UNLOCK(&thread_list);
 	ast_cli(fd, "%d threads listed.\n", count);
 	return 0;
 }
@@ -623,8 +623,8 @@
 
 	ast_cli(fd, FORMAT, "File", "Revision");
 	ast_cli(fd, FORMAT, "----", "--------");
-	AST_LIST_LOCK(&file_versions);
-	AST_LIST_TRAVERSE(&file_versions, iterator, list) {
+	AST_RWLIST_RDLOCK(&file_versions);
+	AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
 		if (havename && strcasecmp(iterator->file, argv[4]))
 			continue;
 
@@ -636,7 +636,7 @@
 		if (havename)
 			break;
 	}
-	AST_LIST_UNLOCK(&file_versions);
+	AST_RWLIST_UNLOCK(&file_versions);
 	if (!havename) {
 		ast_cli(fd, "%d files listed.\n", count_files);
 	}
@@ -658,14 +658,14 @@
 	if (pos != 3)
 		return NULL;
 
-	AST_LIST_LOCK(&file_versions);
-	AST_LIST_TRAVERSE(&file_versions, find, list) {
+	AST_RWLIST_RDLOCK(&file_versions);
+	AST_RWLIST_TRAVERSE(&file_versions, find, list) {
 		if (!strncasecmp(word, find->file, matchlen) && ++which > state) {
 			ret = ast_strdup(find->file);
 			break;
 		}
 	}
-	AST_LIST_UNLOCK(&file_versions);
+	AST_RWLIST_UNLOCK(&file_versions);
 
 	return ret;
 }
@@ -676,28 +676,28 @@
 	int res = -1;
 	struct ast_atexit *ae;
 	ast_unregister_atexit(func);	
-	AST_LIST_LOCK(&atexits);
+	AST_RWLIST_WRLOCK(&atexits);
 	if ((ae = ast_calloc(1, sizeof(*ae)))) {
-		AST_LIST_INSERT_HEAD(&atexits, ae, list);
+		AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
 		ae->func = func;
 		res = 0;
 	}
-	AST_LIST_UNLOCK(&atexits);
+	AST_RWLIST_UNLOCK(&atexits);
 	return res;
 }
 
 void ast_unregister_atexit(void (*func)(void))
 {
 	struct ast_atexit *ae;
-	AST_LIST_LOCK(&atexits);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
+	AST_RWLIST_WRLOCK(&atexits);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
 		if (ae->func == func) {
-			AST_LIST_REMOVE_CURRENT(&atexits, list);
+			AST_RWLIST_REMOVE_CURRENT(&atexits, list);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END
-	AST_LIST_UNLOCK(&atexits);
+	AST_RWLIST_TRAVERSE_SAFE_END
+	AST_RWLIST_UNLOCK(&atexits);
 }
 
 static int fdprint(int fd, const char *s)
@@ -1192,12 +1192,12 @@
 static void ast_run_atexits(void)
 {
 	struct ast_atexit *ae;
-	AST_LIST_LOCK(&atexits);
-	AST_LIST_TRAVERSE(&atexits, ae, list) {
+	AST_RWLIST_RDLOCK(&atexits);
+	AST_RWLIST_TRAVERSE(&atexits, ae, list) {
 		if (ae->func) 
 			ae->func();
 	}
-	AST_LIST_UNLOCK(&atexits);
+	AST_RWLIST_UNLOCK(&atexits);
 }
 
 static void quit_handler(int num, int nice, int safeshutdown, int restart)

Modified: trunk/main/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cdr.c?view=diff&rev=69705&r1=69704&r2=69705
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Mon Jun 18 11:37:14 2007
@@ -63,10 +63,10 @@
 	char name[20];
 	char desc[80];
 	ast_cdrbe be;
-	AST_LIST_ENTRY(ast_cdr_beitem) list;
+	AST_RWLIST_ENTRY(ast_cdr_beitem) list;
 };
 
-static AST_LIST_HEAD_STATIC(be_list, ast_cdr_beitem);
+static AST_RWLIST_HEAD_STATIC(be_list, ast_cdr_beitem);
 
 struct ast_cdr_batch_item {
 	struct ast_cdr *cdr;
@@ -111,25 +111,23 @@
 */
 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
 {
-	struct ast_cdr_beitem *i;
+	struct ast_cdr_beitem *i = NULL;
 
 	if (!name)
 		return -1;
+
 	if (!be) {
 		ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
 		return -1;
 	}
 
-	AST_LIST_LOCK(&be_list);
-	AST_LIST_TRAVERSE(&be_list, i, list) {
-		if (!strcasecmp(name, i->name))
-			break;
-	}
-	AST_LIST_UNLOCK(&be_list);
-
-	if (i) {
-		ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
-		return -1;
+	AST_RWLIST_WRLOCK(&be_list);
+	AST_RWLIST_TRAVERSE(&be_list, i, list) {
+		if (!strcasecmp(name, i->name)) {
+			ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
+			AST_RWLIST_UNLOCK(&be_list);
+			return -1;
+		}
 	}
 
 	if (!(i = ast_calloc(1, sizeof(*i)))) 	
@@ -139,9 +137,8 @@
 	ast_copy_string(i->name, name, sizeof(i->name));
 	ast_copy_string(i->desc, desc, sizeof(i->desc));
 
-	AST_LIST_LOCK(&be_list);
-	AST_LIST_INSERT_HEAD(&be_list, i, list);
-	AST_LIST_UNLOCK(&be_list);
+	AST_RWLIST_INSERT_HEAD(&be_list, i, list);
+	AST_RWLIST_UNLOCK(&be_list);
 
 	return 0;
 }
@@ -151,18 +148,18 @@
 {
 	struct ast_cdr_beitem *i = NULL;
 
-	AST_LIST_LOCK(&be_list);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
+	AST_RWLIST_WRLOCK(&be_list);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
 		if (!strcasecmp(name, i->name)) {
-			AST_LIST_REMOVE_CURRENT(&be_list, list);
+			AST_RWLIST_REMOVE_CURRENT(&be_list, list);
 			if (option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s' CDR backend\n", name);
 			ast_free(i);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&be_list);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&be_list);
 }
 
 /*! Duplicate a CDR record 
@@ -933,11 +930,11 @@
 		ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
 		if (ast_test_flag(cdr, AST_CDR_FLAG_POST_DISABLED))
 			continue;
-		AST_LIST_LOCK(&be_list);
-		AST_LIST_TRAVERSE(&be_list, i, list) {
+		AST_RWLIST_RDLOCK(&be_list);
+		AST_RWLIST_TRAVERSE(&be_list, i, list) {
 			i->be(cdr);
 		}
-		AST_LIST_UNLOCK(&be_list);
+		AST_RWLIST_UNLOCK(&be_list);
 	}
 }
 
@@ -1188,11 +1185,11 @@
 			ast_cli(fd, "CDR maximum batch time: %d second%s\n", batchtime, ESS(batchtime));
 			ast_cli(fd, "CDR next scheduled batch processing time: %ld second%s\n", nextbatchtime, ESS(nextbatchtime));
 		}
-		AST_LIST_LOCK(&be_list);
-		AST_LIST_TRAVERSE(&be_list, beitem, list) {
+		AST_RWLIST_RDLOCK(&be_list);
+		AST_RWLIST_TRAVERSE(&be_list, beitem, list) {
 			ast_cli(fd, "CDR registered backend: %s\n", beitem->name);
 		}
-		AST_LIST_UNLOCK(&be_list);
+		AST_RWLIST_UNLOCK(&be_list);
 	}
 
 	return 0;

Modified: trunk/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/dnsmgr.c?view=diff&rev=69705&r1=69704&r2=69705
==============================================================================
--- trunk/main/dnsmgr.c (original)
+++ trunk/main/dnsmgr.c Mon Jun 18 11:37:14 2007
@@ -60,12 +60,12 @@
 	/*! Set to 1 if the entry changes */
 	int changed:1;
 	ast_mutex_t lock;
-	AST_LIST_ENTRY(ast_dnsmgr_entry) list;
+	AST_RWLIST_ENTRY(ast_dnsmgr_entry) list;
 	/*! just 1 here, but we use calloc to allocate the correct size */
 	char name[1];
 };
 
-static AST_LIST_HEAD_STATIC(entry_list, ast_dnsmgr_entry);
+static AST_RWLIST_HEAD_STATIC(entry_list, ast_dnsmgr_entry);
 
 AST_MUTEX_DEFINE_STATIC(refresh_lock);
 
@@ -97,9 +97,9 @@
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
 
-	AST_LIST_LOCK(&entry_list);
-	AST_LIST_INSERT_HEAD(&entry_list, entry, list);
-	AST_LIST_UNLOCK(&entry_list);
+	AST_RWLIST_WRLOCK(&entry_list);
+	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
+	AST_RWLIST_UNLOCK(&entry_list);
 
 	return entry;
 }
@@ -109,9 +109,9 @@
 	if (!entry)
 		return;
 
-	AST_LIST_LOCK(&entry_list);
-	AST_LIST_REMOVE(&entry_list, entry, list);
-	AST_LIST_UNLOCK(&entry_list);
+	AST_RWLIST_WRLOCK(&entry_list);
+	AST_RWLIST_REMOVE(&entry_list, entry, list);
+	AST_RWLIST_UNLOCK(&entry_list);
 	if (option_verbose > 3)
 		ast_verbose(VERBOSE_PREFIX_4 "removing dns manager for '%s'\n", entry->name);
 
@@ -302,10 +302,10 @@
 
 	ast_cli(fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
 	ast_cli(fd, "Refresh Interval: %d seconds\n", refresh_interval);
-	AST_LIST_LOCK(&entry_list);
-	AST_LIST_TRAVERSE(&entry_list, entry, list)
+	AST_RWLIST_RDLOCK(&entry_list);
+	AST_RWLIST_TRAVERSE(&entry_list, entry, list)
 		count++;
-	AST_LIST_UNLOCK(&entry_list);
+	AST_RWLIST_UNLOCK(&entry_list);
 	ast_cli(fd, "Number of entries: %d\n", count);
 
 	return 0;




More information about the asterisk-commits mailing list