aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/lock.h
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-29 17:35:19 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-29 17:35:19 +0000
commit3db76e85a49901a2049ec3d430685d5c32f7aeba (patch)
treee50351cd486e0a7298a3de06f70964fe2b1de70b /include/asterisk/lock.h
parentfbdb5ab9e626c212baf6ace1e347676e5cf46bf8 (diff)
Merged revisions 118953 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r118953 | tilghman | 2008-05-29 12:20:16 -0500 (Thu, 29 May 2008) | 3 lines Add some debugging code that ensures that when we do deadlock avoidance, we don't lose the information about how a lock was originally acquired. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@118955 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/lock.h')
-rw-r--r--include/asterisk/lock.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 7f8d00eb6..5a9bc252f 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -220,7 +220,7 @@ static inline void __dump_backtrace(struct ast_bt *bt, int canlog)
{
char **strings;
- size_t i;
+ ssize_t i;
strings = backtrace_symbols(bt->addresses, bt->num_frames);
@@ -241,6 +241,38 @@ static inline void __dump_backtrace(struct ast_bt *bt, int canlog)
*/
void log_show_lock(void *this_lock_addr);
+/*!
+ * \brief retrieve lock info for the specified mutex
+ *
+ * this gets called during deadlock avoidance, so that the information may
+ * be preserved as to what location originally acquired the lock.
+ */
+#if !defined(LOW_MEMORY)
+int ast_find_lock_info(void *lock_addr, const char **filename, int *lineno, const char **func, const char **mutex_name);
+#else
+#define ast_find_lock_info(a,b,c,d,e) -1
+#endif
+
+/*!
+ * \brief Unlock a lock briefly
+ *
+ * used during deadlock avoidance, to preserve the original location where
+ * a lock was originally acquired.
+ */
+#define DEADLOCK_AVOIDANCE(lock) \
+ do { \
+ const char *__filename, *__func, *__mutex_name; \
+ int __lineno; \
+ int __res = ast_find_lock_info(lock, &__filename, &__lineno, &__func, &__mutex_name); \
+ ast_mutex_unlock(lock); \
+ usleep(1); \
+ if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
+ ast_mutex_lock(lock); \
+ } else { \
+ __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+ } \
+ } while (0)
+
static void __attribute__((constructor)) init_empty_mutex(void)
{
memset(&empty_mutex, 0, sizeof(empty_mutex));