mirror of
https://github.com/asterisk/asterisk.git
synced 2025-12-04 04:01:56 +00:00
vector: Update API to be more flexible.
Made the vector macro API be more like linked lists. 1) Added a name parameter to ast_vector() to name the vector struct. 2) Made the API take a pointer to the vector struct instead of the struct itself. 3) Added an element cleanup macro/function parameter when removing an element from the vector for ast_vector_remove_cmp_unordered() and ast_vector_remove_elem_unordered(). 4) Added ast_vector_get_addr() in case the vector element is not a simple pointer. * Converted an inline vector usage in stasis_message_router to use the vector API. It needed the API improvements so it could be converted. * Fixed topic reference leak in router_dtor() when the stasis_message_router is destroyed. * Fixed deadlock potential in stasis_forward_all() and stasis_forward_cancel(). Locking two topics at the same time requires deadlock avoidance. * Made internal_stasis_subscribe() tolerant of a NULL topic. * Made stasis_message_router_add(), stasis_message_router_add_cache_update(), stasis_message_router_remove(), and stasis_message_router_remove_cache_update() tolerant of a NULL message_type. * Promoted a LOG_DEBUG message to LOG_ERROR as intended in dispatch_message(). Review: https://reviewboard.asterisk.org/r/2903/ ........ Merged revisions 402429 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402430 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -339,6 +339,28 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
|
||||
* used during deadlock avoidance, to preserve the original location where
|
||||
* a lock was originally acquired.
|
||||
*/
|
||||
#define AO2_DEADLOCK_AVOIDANCE(obj) \
|
||||
do { \
|
||||
char __filename[80], __func[80], __mutex_name[80]; \
|
||||
int __lineno; \
|
||||
int __res = ast_find_lock_info(ao2_object_get_lockaddr(obj), __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
|
||||
int __res2 = ao2_unlock(obj); \
|
||||
usleep(1); \
|
||||
if (__res < 0) { /* Could happen if the ao2 object does not have a mutex. */ \
|
||||
if (__res2) { \
|
||||
ast_log(LOG_WARNING, "Could not unlock ao2 object '%s': %s and no lock info found! I will NOT try to relock.\n", #obj, strerror(__res2)); \
|
||||
} else { \
|
||||
ao2_lock(obj); \
|
||||
} \
|
||||
} else { \
|
||||
if (__res2) { \
|
||||
ast_log(LOG_WARNING, "Could not unlock ao2 object '%s': %s. {{{Originally locked at %s line %d: (%s) '%s'}}} I will NOT try to relock.\n", #obj, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
|
||||
} else { \
|
||||
__ao2_lock(obj, AO2_LOCK_REQ_MUTEX, __filename, __func, __lineno, __mutex_name); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHANNEL_DEADLOCK_AVOIDANCE(chan) \
|
||||
do { \
|
||||
char __filename[80], __func[80], __mutex_name[80]; \
|
||||
@@ -493,12 +515,17 @@ static inline void delete_reentrancy_cs(struct ast_lock_track **plt)
|
||||
|
||||
#else /* !DEBUG_THREADS */
|
||||
|
||||
#define CHANNEL_DEADLOCK_AVOIDANCE(chan) \
|
||||
#define AO2_DEADLOCK_AVOIDANCE(obj) \
|
||||
ao2_unlock(obj); \
|
||||
usleep(1); \
|
||||
ao2_lock(obj);
|
||||
|
||||
#define CHANNEL_DEADLOCK_AVOIDANCE(chan) \
|
||||
ast_channel_unlock(chan); \
|
||||
usleep(1); \
|
||||
ast_channel_lock(chan);
|
||||
|
||||
#define DEADLOCK_AVOIDANCE(lock) \
|
||||
#define DEADLOCK_AVOIDANCE(lock) \
|
||||
do { \
|
||||
int __res; \
|
||||
if (!(__res = ast_mutex_unlock(lock))) { \
|
||||
|
||||
Reference in New Issue
Block a user