aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-29 17:42:28 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-29 17:42:28 +0000
commit5f08a3ee3a2125e69352c5404d7f57bed9b480f6 (patch)
tree1423c2f41c452512d73905e0542e62bb6c598735 /include
parent119443fc3f48cf7d749e58ea9c7d47af6511a3b4 (diff)
Merged revisions 118955,118957 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r118955 | tilghman | 2008-05-29 12:35:19 -0500 (Thu, 29 May 2008) | 11 lines 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. ........ ................ r118957 | tilghman | 2008-05-29 12:39:50 -0500 (Thu, 29 May 2008) | 10 lines Merged revisions 118954 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r118954 | tilghman | 2008-05-29 12:33:01 -0500 (Thu, 29 May 2008) | 2 lines Define also when not DEBUG_THREADS ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@118958 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/lock.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index edc285a5f..e7dfb3075 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -186,6 +186,38 @@ void ast_remove_lock_info(void *lock_addr);
#define ast_remove_lock_info(ignore)
#endif
+/*!
+ * \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));
@@ -1035,6 +1067,11 @@ static inline int _ast_rwlock_trywrlock(ast_rwlock_t *lock, const char *name,
#else /* !DEBUG_THREADS */
+#define DEADLOCK_AVOIDANCE(lock) \
+ ast_mutex_lock(lock); \
+ usleep(1); \
+ ast_mutex_unlock(lock);
+
static inline int ast_rwlock_init(ast_rwlock_t *prwlock)
{
int res;