[asterisk-commits] file: trunk r53111 - /trunk/main/devicestate.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 1 17:39:02 MST 2007


Author: file
Date: Thu Feb  1 18:39:01 2007
New Revision: 53111

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53111
Log:
Read/write lockify the devicestate stuff a bit.

Modified:
    trunk/main/devicestate.c

Modified: trunk/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/devicestate.c?view=diff&rev=53111&r1=53110&r2=53111
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Thu Feb  1 18:39:01 2007
@@ -144,21 +144,21 @@
 struct devstate_prov {
 	char label[40];
 	ast_devstate_prov_cb_type callback;
-	AST_LIST_ENTRY(devstate_prov) list;
+	AST_RWLIST_ENTRY(devstate_prov) list;
 };
 
 /*! \brief A list of providers */
-static AST_LIST_HEAD_STATIC(devstate_provs, devstate_prov);
+static AST_RWLIST_HEAD_STATIC(devstate_provs, devstate_prov);
 
 /*! \brief  A device state watcher (callback) */
 struct devstate_cb {
 	void *data;
 	ast_devstate_cb_type callback;	/*!< Where to report when state changes */
-	AST_LIST_ENTRY(devstate_cb) list;
+	AST_RWLIST_ENTRY(devstate_cb) list;
 };
 
 /*! \brief A device state watcher list */
-static AST_LIST_HEAD_STATIC(devstate_cbs, devstate_cb);
+static AST_RWLIST_HEAD_STATIC(devstate_cbs, devstate_cb);
 
 struct state_change {
 	AST_LIST_ENTRY(state_change) list;
@@ -277,9 +277,9 @@
 	devprov->callback = callback;
 	ast_copy_string(devprov->label, label, sizeof(devprov->label));
 
-	AST_LIST_LOCK(&devstate_provs);
-	AST_LIST_INSERT_HEAD(&devstate_provs, devprov, list);
-	AST_LIST_UNLOCK(&devstate_provs);
+	AST_RWLIST_WRLOCK(&devstate_provs);
+	AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list);
+	AST_RWLIST_UNLOCK(&devstate_provs);
 
 	return 0;
 }
@@ -289,16 +289,16 @@
 {
 	struct devstate_prov *devcb;
 
-	AST_LIST_LOCK(&devstate_provs);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
+	AST_RWLIST_WRLOCK(&devstate_provs);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
 		if (!strcasecmp(devcb->label, label)) {
-			AST_LIST_REMOVE_CURRENT(&devstate_provs, list);
+			AST_RWLIST_REMOVE_CURRENT(&devstate_provs, list);
 			free(devcb);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&devstate_provs);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&devstate_provs);
 }
 
 /*! \brief Get provider device state */
@@ -308,8 +308,8 @@
 	int res = AST_DEVICE_INVALID;
 
 
-	AST_LIST_LOCK(&devstate_provs);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devprov, list) {
+	AST_RWLIST_RDLOCK(&devstate_provs);
+	AST_RWLIST_TRAVERSE(&devstate_provs, devprov, list) {
 		if (option_debug > 4)
 			ast_log(LOG_DEBUG, "Checking provider %s with %s\n", devprov->label, provider);
 
@@ -318,8 +318,7 @@
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&devstate_provs);
+	AST_RWLIST_UNLOCK(&devstate_provs);
 	return res;
 }
 
@@ -334,9 +333,9 @@
 	devcb->data = data;
 	devcb->callback = callback;
 
-	AST_LIST_LOCK(&devstate_cbs);
-	AST_LIST_INSERT_HEAD(&devstate_cbs, devcb, list);
-	AST_LIST_UNLOCK(&devstate_cbs);
+	AST_RWLIST_WRLOCK(&devstate_cbs);
+	AST_RWLIST_INSERT_HEAD(&devstate_cbs, devcb, list);
+	AST_RWLIST_UNLOCK(&devstate_cbs);
 
 	return 0;
 }
@@ -346,16 +345,16 @@
 {
 	struct devstate_cb *devcb;
 
-	AST_LIST_LOCK(&devstate_cbs);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_cbs, devcb, list) {
+	AST_RWLIST_WRLOCK(&devstate_cbs);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_cbs, devcb, list) {
 		if ((devcb->callback == callback) && (devcb->data == data)) {
-			AST_LIST_REMOVE_CURRENT(&devstate_cbs, list);
+			AST_RWLIST_REMOVE_CURRENT(&devstate_cbs, list);
 			free(devcb);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&devstate_cbs);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&devstate_cbs);
 }
 
 /*! \brief Notify callback watchers of change, and notify PBX core for hint updates
@@ -370,10 +369,10 @@
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state));
 
-	AST_LIST_LOCK(&devstate_cbs);
-	AST_LIST_TRAVERSE(&devstate_cbs, devcb, list)
+	AST_RWLIST_RDLOCK(&devstate_cbs);
+	AST_RWLIST_TRAVERSE(&devstate_cbs, devcb, list)
 		devcb->callback(device, state, devcb->data);
-	AST_LIST_UNLOCK(&devstate_cbs);
+	AST_RWLIST_UNLOCK(&devstate_cbs);
 
 	ast_hint_state_changed(device);
 }



More information about the asterisk-commits mailing list