#endif
#include "asterisk/logger.h"
+#include "asterisk/compiler.h"
#define AST_PTHREADT_NULL (pthread_t) -1
#define AST_PTHREADT_STOP (pthread_t) -2
char __filename[80], __func[80], __mutex_name[80]; \
int __lineno; \
int __res = ast_find_lock_info(ao2_object_get_lockaddr(chan), __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 { \
- __ao2_lock(chan, __filename, __func, __lineno, __mutex_name); \
+ 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 { \
+ __ao2_lock(chan, __filename, __func, __lineno, __mutex_name); \
+ } \
} \
} while (0)
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)
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
*/
#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)
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)