summaryrefslogtreecommitdiff
path: root/indications.c
diff options
context:
space:
mode:
authorLuigi Rizzo <rizzo@icir.org>2006-03-30 17:10:11 +0000
committerLuigi Rizzo <rizzo@icir.org>2006-03-30 17:10:11 +0000
commit48864ab877d4e9038f3f8c0e119ab7e02c07523c (patch)
tree56636b4d708638cdb380dc76672be39341eec1f9 /indications.c
parent6d2fbc0b909d9802f67345630cb967311d72eb1c (diff)
do not export the tzlock and the list head, and introduce a new method,
ast_walk_indications(), to walk through the list of indications. The new method returns an unlocked record, which is no different from the behaviour of other existing methods in indications.c (i.e. they all need to be fixed, with refcounts or some similar method). Note that ast_walk_indications() uses the pointer argument only as a search key, so its implementation is completely safe. In turn, this change allows the removal of AST_MUTEX_DEFINE_EXPORTED. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@16532 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'indications.c')
-rw-r--r--indications.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/indications.c b/indications.c
index 2d2ca6896..9b632de98 100644
--- a/indications.c
+++ b/indications.c
@@ -330,22 +330,28 @@ void ast_playtones_stop(struct ast_channel *chan)
/*--------------------------------------------*/
-struct tone_zone *tone_zones;
+static struct tone_zone *tone_zones;
static struct tone_zone *current_tonezone;
/* Protect the tone_zones list (highly unlikely that two things would change
* it at the same time, but still! */
-AST_MUTEX_DEFINE_EXPORTED(tzlock);
-/* XXX note - this is the only instance of AST_MUTEX_DEFINE_EXPORTED()
- * in the entire asterisk code base, and should be replaced by a static one.
- * The mutex is declared exported because it is accessed
- * by other files, namely res/snmp/agent.c and res/res_indications.c.
- * However there are also unprotected accesses to the list, because
- * some of the functions below export pointers to the elements, so
- * the entire mechanism is useless.
- * This needs to be fixed by providing functions to navigate in the
- * list, and refcounts to prevent entries from being destroyed.
- */
+AST_MUTEX_DEFINE_STATIC(tzlock);
+
+struct tone_zone *ast_walk_indications(const struct tone_zone *cur)
+{
+ struct tone_zone *tz;
+
+ if (cur == NULL)
+ return tone_zones;
+ ast_mutex_lock(&tzlock);
+ for (tz = tone_zones; tz; tz = tz->next)
+ if (tz == cur)
+ break;
+ if (tz)
+ tz = tz->next;
+ ast_mutex_unlock(&tzlock);
+ return tz;
+}
/* Set global indication country */
int ast_set_indication_country(const char *country)