channel_internal_api.c: Replace some code with ao2_replace().

Use ao2_replace() instead of ao2_cleanup(); ao2_bump().

ao2_replace() has the advantange of not altering the ref count if the
replaced pointer is the same.

Review: https://reviewboard.asterisk.org/r/3904/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@420992 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2014-08-14 15:54:47 +00:00
parent cd81f920a4
commit 7eb4ee9b2f
2 changed files with 9 additions and 16 deletions

View File

@@ -6244,8 +6244,7 @@ static int ast_channel_make_compatible_helper(struct ast_channel *from, struct a
ast_format_get_sample_rate(best_src_fmt) : ast_format_get_sample_rate(best_dst_fmt); ast_format_get_sample_rate(best_src_fmt) : ast_format_get_sample_rate(best_dst_fmt);
/* pick the best signed linear format based upon what preserves the sample rate the best. */ /* pick the best signed linear format based upon what preserves the sample rate the best. */
ao2_ref(best_src_fmt, -1); ao2_replace(best_src_fmt, ast_format_cache_get_slin_by_rate(best_sample_rate));
best_src_fmt = ao2_bump(ast_format_cache_get_slin_by_rate(best_sample_rate));
} }
} }

View File

@@ -196,9 +196,9 @@ struct ast_channel {
int alertpipe[2]; int alertpipe[2];
struct ast_format_cap *nativeformats; /*!< Kinds of data this channel can natively handle */ struct ast_format_cap *nativeformats; /*!< Kinds of data this channel can natively handle */
struct ast_format *readformat; /*!< Requested read format (after translation) */ struct ast_format *readformat; /*!< Requested read format (after translation) */
struct ast_format *writeformat; /*!< Requested write format (after translation) */ struct ast_format *writeformat; /*!< Requested write format (before translation) */
struct ast_format *rawreadformat; /*!< Raw read format (before translation) */ struct ast_format *rawreadformat; /*!< Raw read format (before translation) */
struct ast_format *rawwriteformat; /*!< Raw write format (before translation) */ struct ast_format *rawwriteformat; /*!< Raw write format (after translation) */
unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */ unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
#ifdef HAVE_EPOLL #ifdef HAVE_EPOLL
int epfd; int epfd;
@@ -828,8 +828,7 @@ struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
} }
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value) void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
{ {
ao2_cleanup(chan->nativeformats); ao2_replace(chan->nativeformats, value);
chan->nativeformats = ao2_bump(value);
} }
struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan) struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
{ {
@@ -954,28 +953,23 @@ void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state valu
} }
void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format) void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format)
{ {
ao2_cleanup(chan->oldwriteformat); ao2_replace(chan->oldwriteformat, format);
chan->oldwriteformat = ao2_bump(format);
} }
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format) void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
{ {
ao2_cleanup(chan->rawreadformat); ao2_replace(chan->rawreadformat, format);
chan->rawreadformat = ao2_bump(format);
} }
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format) void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
{ {
ao2_cleanup(chan->rawwriteformat); ao2_replace(chan->rawwriteformat, format);
chan->rawwriteformat = ao2_bump(format);
} }
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format) void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
{ {
ao2_cleanup(chan->readformat); ao2_replace(chan->readformat, format);
chan->readformat = ao2_bump(format);
} }
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format) void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
{ {
ao2_cleanup(chan->writeformat); ao2_replace(chan->writeformat, format);
chan->writeformat = ao2_bump(format);
} }
struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan) struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
{ {