aboutsummaryrefslogtreecommitdiffstats
path: root/indications.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-30 17:10:11 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-30 17:10:11 +0000
commit70020a2853bd51930d36fd997fc71eedfe71eb6e (patch)
tree56636b4d708638cdb380dc76672be39341eec1f9 /indications.c
parentcd3c76f7f1e6a0655e035b8ab8d164109d31f92c (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: http://svn.digium.com/svn/asterisk/trunk@16532 f38db490-d61c-443f-a65b-d21fe96a405b
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)