lock.c: Separate DETECT_DEADLOCKS from DEBUG_THREADS

Previously, DETECT_DEADLOCKS depended on DEBUG_THREADS.
Unfortunately, DEBUG_THREADS adds a lot of lock tracking overhead
to all of the lock lifecycle calls whereas DETECT_DEADLOCKS just
causes the lock calls to loop over trylock in 200us intervals until
the lock is obtained and spits out log messages if it takes more
than 5 seconds.  From a code perspective, the only reason they were
tied together was for logging.  So... The ifdefs in lock.c were
refactored to allow DETECT_DEADLOCKS to be enabled without
also enabling DEBUG_THREADS.

Resolves: #321

UserNote: You no longer need to select DEBUG_THREADS to use
DETECT_DEADLOCKS.  This removes a significant amount of overhead
if you just want to detect possible deadlocks vs needing full
lock tracing.

(cherry picked from commit 04df168656)
This commit is contained in:
George Joseph
2023-09-13 09:18:04 -06:00
committed by Asterisk Development Team
parent 58a4294631
commit af51fe730e
3 changed files with 44 additions and 23 deletions

View File

@@ -134,14 +134,15 @@ struct ast_lock_track_flags {
*/
struct ast_mutex_info {
pthread_mutex_t mutex;
#if !defined(DEBUG_THREADS) && !defined(DEBUG_THREADS_LOOSE_ABI)
#if !defined(DEBUG_THREADS) && !defined(DEBUG_THREADS_LOOSE_ABI) && \
!defined(DETECT_DEADLOCKS)
/*!
* These fields are renamed to ensure they are never used when
* DEBUG_THREADS is not defined.
*/
struct ast_lock_track *_track;
struct ast_lock_track_flags _flags;
#elif defined(DEBUG_THREADS)
#elif defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
/*! Track which thread holds this mutex. */
struct ast_lock_track *track;
struct ast_lock_track_flags flags;
@@ -155,14 +156,15 @@ struct ast_mutex_info {
*/
struct ast_rwlock_info {
pthread_rwlock_t lock;
#if !defined(DEBUG_THREADS) && !defined(DEBUG_THREADS_LOOSE_ABI)
#if !defined(DEBUG_THREADS) && !defined(DEBUG_THREADS_LOOSE_ABI) && \
!defined(DETECT_DEADLOCKS)
/*!
* These fields are renamed to ensure they are never used when
* DEBUG_THREADS is not defined.
*/
struct ast_lock_track *_track;
struct ast_lock_track_flags _flags;
#elif defined(DEBUG_THREADS)
#elif defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
/*! Track which thread holds this lock */
struct ast_lock_track *track;
struct ast_lock_track_flags flags;