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
This commit is contained in:
Luigi Rizzo
2006-03-30 17:10:11 +00:00
parent 6d2fbc0b90
commit 48864ab877
4 changed files with 40 additions and 47 deletions

View File

@@ -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)