aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-03 02:43:06 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-03 02:43:06 +0000
commit724e4e9b9c6c9d12d6545a6f1b084aaf2cc3ba98 (patch)
tree416eeb3ce55d656f75708ad9ed351525270ef34c /include
parent6e39b348bdccc39c8f5a9997c0cc1920857c6f6b (diff)
Merged revisions 273830 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r273830 | tilghman | 2010-07-02 21:36:31 -0500 (Fri, 02 Jul 2010) | 16 lines Merged revisions 273793 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r273793 | tilghman | 2010-07-02 16:36:39 -0500 (Fri, 02 Jul 2010) | 9 lines Have the DEADLOCK_AVOIDANCE macro warn when an unlock fails, to help catch potentially large software bugs. (closes issue #17407) Reported by: pdf Patches: 20100527__issue17407.diff.txt uploaded by tilghman (license 14) Review: https://reviewboard.asterisk.org/r/751/ ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@273831 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/lock.h55
1 files changed, 43 insertions, 12 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index a000eca06..1dfcbf7c9 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -59,6 +59,7 @@
#include "asterisk/time.h"
#endif
#include "asterisk/logger.h"
+#include "asterisk/compiler.h"
/* internal macro to profile mutexes. Only computes the delay on
* non-blocking calls.
@@ -273,12 +274,20 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
char __filename[80], __func[80], __mutex_name[80]; \
int __lineno; \
int __res = ast_find_lock_info(&chan->lock_dont_use, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
- ast_channel_unlock(chan); \
+ int __res2 = ast_channel_unlock(chan); \
usleep(1); \
if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
- ast_channel_lock(chan); \
+ if (__res2) { \
+ ast_log(LOG_WARNING, "Could not unlock channel '%s': %s and no lock info found! I will NOT try to relock.\n", #chan, strerror(__res2)); \
+ } else { \
+ ast_channel_lock(chan); \
+ } \
} else { \
- __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, &chan->lock_dont_use); \
+ if (__res2) { \
+ ast_log(LOG_WARNING, "Could not unlock channel '%s': %s. {{{Originally locked at %s line %d: (%s) '%s'}}} I will NOT try to relock.\n", #chan, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+ } else { \
+ __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, &chan->lock_dont_use); \
+ } \
} \
} while (0)
@@ -287,12 +296,20 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
char __filename[80], __func[80], __mutex_name[80]; \
int __lineno; \
int __res = ast_find_lock_info(lock, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
- ast_mutex_unlock(lock); \
+ int __res2 = ast_mutex_unlock(lock); \
usleep(1); \
if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
- ast_mutex_lock(lock); \
+ if (__res2 == 0) { \
+ ast_mutex_lock(lock); \
+ } else { \
+ ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s and no lock info found! I will NOT try to relock.\n", #lock, strerror(__res2)); \
+ } \
} else { \
- __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+ if (__res2 == 0) { \
+ __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+ } else { \
+ ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s. {{{Originally locked at %s line %d: (%s) '%s'}}} I will NOT try to relock.\n", #lock, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+ } \
} \
} while (0)
@@ -313,7 +330,7 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
char __filename[80], __func[80], __mutex_name[80]; \
int __lineno; \
int __res = ast_find_lock_info(lock, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
- ast_mutex_unlock(lock);
+ int __res2 = ast_mutex_unlock(lock);
/*!
* \brief Deadlock avoidance lock
@@ -329,9 +346,17 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
*/
#define DLA_LOCK(lock) \
if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
- ast_mutex_lock(lock); \
+ if (__res2) { \
+ ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s and no lock info found! I will NOT try to relock.\n", #lock, strerror(__res2)); \
+ } else { \
+ ast_mutex_lock(lock); \
+ } \
} else { \
- __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+ if (__res2) { \
+ ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s. {{{Originally locked at %s line %d: (%s) '%s'}}} I will NOT try to relock.\n", #lock, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+ } else { \
+ __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+ } \
} \
} while (0)
@@ -1670,9 +1695,15 @@ static inline int _ast_rwlock_trywrlock(ast_rwlock_t *t, const char *name,
ast_channel_lock(chan);
#define DEADLOCK_AVOIDANCE(lock) \
- ast_mutex_unlock(lock); \
- usleep(1); \
- ast_mutex_lock(lock);
+ do { \
+ int __res; \
+ if (!(__res = ast_mutex_unlock(lock))) { \
+ usleep(1); \
+ ast_mutex_lock(lock); \
+ } else { \
+ ast_log(LOG_WARNING, "Failed to unlock mutex '%s' (%s). I will NOT try to relock. {{{ THIS IS A BUG. }}}\n", #lock, strerror(__res)); \
+ } \
+ } while (0)
#define DLA_UNLOCK(lock) ast_mutex_unlock(lock)