]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
A change to the way channel locks are handled when DEBUG_CHANNEL_LOCKS is defined.
authorMark Michelson <mmichelson@digium.com>
Tue, 13 May 2008 23:47:49 +0000 (23:47 +0000)
committerMark Michelson <mmichelson@digium.com>
Tue, 13 May 2008 23:47:49 +0000 (23:47 +0000)
After debugging a deadlock, it was noticed that when DEBUG_CHANNEL_LOCKS
is enabled in menuselect, the actual origin of channel locks is obscured
by the fact that all channel locks appear to happen in the function
ast_channel_lock(). This code change redefines ast_channel_lock to be a
macro which maps to __ast_channel_lock(), which then relays the proper
file name, line number, and function name information to the core lock
functions so that this information will be displayed in the case that
there is some sort of locking error or core show locks is issued.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@116088 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/lock.h
main/channel.c

index cc68a13aa35452d55153a553d250dde0e7bab22c..2570ee7bb9b8ee9b54b2f8833c41d666af18bac1 100644 (file)
@@ -1196,18 +1196,21 @@ AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
 
 struct ast_channel;
 
+#define ast_channel_lock(a) __ast_channel_lock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Lock AST channel (and print debugging output)
 \note You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int ast_channel_lock(struct ast_channel *chan);
+int __ast_channel_lock(struct ast_channel *chan, const char *file, int lineno, const char *func);
 
+#define ast_channel_unlock(a) __ast_channel_unlock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Unlock AST channel (and print debugging output)
 \note You need to enable DEBUG_CHANNEL_LOCKS for this function
 */
-int ast_channel_unlock(struct ast_channel *chan);
+int __ast_channel_unlock(struct ast_channel *chan, const char *file, int lineno, const char *func);
 
+#define ast_channel_trylock(a) __ast_channel_trylock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Lock AST channel (and print debugging output)
 \note   You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int ast_channel_trylock(struct ast_channel *chan);
+int __ast_channel_trylock(struct ast_channel *chan, const char *file, int lineno, const char *func);
 #endif
 
 #endif /* _ASTERISK_LOCK_H */
index f61d365b70a9d099f621ddce8080582db8f769a1..d9ab77c382177684cb29f376385db5543d2065d0 100644 (file)
@@ -4534,7 +4534,7 @@ const char *channelreloadreason2txt(enum channelreloadreason reason)
 /*! \brief Unlock AST channel (and print debugging output) 
 \note You need to enable DEBUG_CHANNEL_LOCKS for this function
 */
-int ast_channel_unlock(struct ast_channel *chan)
+int __ast_channel_unlock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
 {
        int res = 0;
        if (option_debug > 2) 
@@ -4545,8 +4545,11 @@ int ast_channel_unlock(struct ast_channel *chan)
                        ast_log(LOG_DEBUG, "::::==== Unlocking non-existing channel \n");
                return 0;
        }
-
+#ifdef DEBUG_THREADS
+       res = __ast_pthread_mutex_unlock(filename, lineno, func, "(channel lock)", &chan->lock);
+#else
        res = ast_mutex_unlock(&chan->lock);
+#endif
 
        if (option_debug > 2) {
 #ifdef DEBUG_THREADS
@@ -4573,14 +4576,18 @@ int ast_channel_unlock(struct ast_channel *chan)
 
 /*! \brief Lock AST channel (and print debugging output)
 \note You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int ast_channel_lock(struct ast_channel *chan)
+int __ast_channel_lock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
 {
        int res;
 
        if (option_debug > 3)
                ast_log(LOG_DEBUG, "====:::: Locking AST channel %s\n", chan->name);
 
+#ifdef DEBUG_THREADS
+       res = __ast_pthread_mutex_lock(filename, lineno, func, "(channel lock)", &chan->lock);
+#else
        res = ast_mutex_lock(&chan->lock);
+#endif
 
        if (option_debug > 3) {
 #ifdef DEBUG_THREADS
@@ -4605,14 +4612,17 @@ int ast_channel_lock(struct ast_channel *chan)
 
 /*! \brief Lock AST channel (and print debugging output)
 \note  You need to enable DEBUG_CHANNEL_LOCKS for this function */
-int ast_channel_trylock(struct ast_channel *chan)
+int __ast_channel_trylock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
 {
        int res;
 
        if (option_debug > 2)
                ast_log(LOG_DEBUG, "====:::: Trying to lock AST channel %s\n", chan->name);
-
+#ifdef DEBUG_THREADS
+       res = __ast_pthread_mutex_trylock(filename, lineno, func, "(channel lock)", &chan->lock);
+#else
        res = ast_mutex_trylock(&chan->lock);
+#endif
 
        if (option_debug > 2) {
 #ifdef DEBUG_THREADS