[Asterisk-code-review] Provide SCOPED LOCK variant for AST RWLIST. (asterisk[master])
Joerg Sonnenberger
asteriskteam at digium.com
Tue Jun 2 17:39:14 CDT 2015
Joerg Sonnenberger has uploaded a new change for review.
https://gerrit.asterisk.org/573
Change subject: Provide SCOPED_LOCK variant for AST_RWLIST.
......................................................................
Provide SCOPED_LOCK variant for AST_RWLIST.
When SCOPED_LOCK is used with AST_RWLIST_UNLOCK as dtor,
the dtor expression is parametrized by the head type.
Introduce a variant to move this parametrization into the
SCOPED_LOCK definition and use the fixed ast_rwlock_unlock for
RAII_VAR.
Change-Id: I201fb77d68ef56f5e0388b256c4c0d624c0277e8
---
M include/asterisk/lock.h
M main/channel.c
M res/res_stasis.c
3 files changed, 15 insertions(+), 5 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/73/573/1
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 35a244b..50c9cee 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -615,6 +615,16 @@
#define SCOPED_WRLOCK(varname, lock) SCOPED_LOCK(varname, (lock), ast_rwlock_wrlock, ast_rwlock_unlock)
/*!
+ * \brief scoped lock specialization for read locks of AST_RWLIST
+ */
+#define SCOPED_RWLIST_RDLOCK(varname, head) SCOPED_LOCK(varname, &(head)->lock, ast_rwlock_rdlock, ast_rwlock_unlock)
+
+/*!
+ * \brief scoped lock specialization for write locks of AST_RWLIST
+ */
+#define SCOPED_RWLIST_WRLOCK(varname, head) SCOPED_LOCK(varname, &(head)->lock, ast_rwlock_wrlock, ast_rwlock_unlock)
+
+/*!
* \brief scoped lock specialization for ao2 mutexes.
*/
#define SCOPED_AO2LOCK(varname, obj) SCOPED_LOCK(varname, (obj), ao2_lock, ao2_unlock)
diff --git a/main/channel.c b/main/channel.c
index fbdf17b..9539071 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -7685,7 +7685,7 @@
RAII_VAR(struct varshead *, ret, NULL, ao2_cleanup);
RAII_VAR(struct ast_str *, tmp, NULL, ast_free);
struct manager_channel_variable *mcv;
- SCOPED_LOCK(lock, &channelvars, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+ SCOPED_RWLIST_RDLOCK(lock, &channelvars);
if (AST_LIST_EMPTY(&channelvars)) {
return NULL;
diff --git a/res/res_stasis.c b/res/res_stasis.c
index 631af1e..df7cedb 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -1529,7 +1529,7 @@
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
{
- SCOPED_LOCK(lock, &event_sources, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+ SCOPED_RWLIST_WRLOCK(lock, &event_sources);
AST_LIST_INSERT_TAIL(&event_sources, obj, next);
/* only need to bump the module ref on non-core sources because the
core ones are [un]registered by this module. */
@@ -1541,7 +1541,7 @@
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
{
struct stasis_app_event_source *source;
- SCOPED_LOCK(lock, &event_sources, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+ SCOPED_RWLIST_WRLOCK(lock, &event_sources);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&event_sources, source, next) {
if (source == obj) {
AST_RWLIST_REMOVE_CURRENT(next);
@@ -1570,7 +1570,7 @@
const struct stasis_app *app, struct ast_json *json)
{
struct stasis_app_event_source *source;
- SCOPED_LOCK(lock, &event_sources, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+ SCOPED_RWLIST_RDLOCK(lock, &event_sources);
AST_LIST_TRAVERSE(&event_sources, source, next) {
if (source->to_json) {
source->to_json(app, json);
@@ -1609,7 +1609,7 @@
static struct stasis_app_event_source *app_event_source_find(const char *uri)
{
struct stasis_app_event_source *source;
- SCOPED_LOCK(lock, &event_sources, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+ SCOPED_RWLIST_RDLOCK(lock, &event_sources);
AST_LIST_TRAVERSE(&event_sources, source, next) {
if (ast_begins_with(uri, source->scheme)) {
return source;
--
To view, visit https://gerrit.asterisk.org/573
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I201fb77d68ef56f5e0388b256c4c0d624c0277e8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joerg Sonnenberger <joerg at bec.de>
More information about the asterisk-code-review
mailing list