*/
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;
*/
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;
#undef pthread_cond_wait
#undef pthread_cond_timedwait
-#if defined(DEBUG_THREADS)
+#if defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
#define log_mutex_error(canlog, ...) \
do { \
if (canlog) { \
int res;
pthread_mutexattr_t attr;
-#ifdef DEBUG_THREADS
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
+#if defined(DEBUG_THREADS) && defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && \
+ defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
int canlog = tracking && strcmp(filename, "logger.c");
}
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+#if defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
t->track = NULL;
t->flags.tracking = tracking;
t->flags.setup = 0;
{
int res;
+#if defined(DETECT_DEADLOCKS) || defined(DEBUG_THREADS)
+ int canlog = t->flags.tracking && strcmp(filename, "logger.c");
+#endif
+
#ifdef DEBUG_THREADS
struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
- int canlog = t->flags.tracking && strcmp(filename, "logger.c");
struct ast_bt *bt = NULL;
if (lt) {
}
#endif /* DEBUG_THREADS */
-#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
+#if defined(DETECT_DEADLOCKS)
{
time_t seconds = time(NULL);
time_t wait_time, reported_wait = 0;
if (wait_time > reported_wait && (wait_time % 5) == 0) {
log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
filename, lineno, func, (int) wait_time, mutex_name);
+#ifdef DEBUG_THREADS
if (lt) {
ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
#endif
ast_reentrancy_unlock(lt);
}
+#endif
reported_wait = wait_time;
if ((int) wait_time < 10) { /* Only emit an event when a deadlock starts, not every 5 seconds */
/*** DOCUMENTATION
return res;
}
-int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
+int __ast_rwlock_init(int tracking, const char *filename, int lineno, \
+ const char *func, const char *rwlock_name, ast_rwlock_t *t)
{
int res;
pthread_rwlockattr_t attr;
-#ifdef DEBUG_THREADS
-#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
+#if defined(DEBUG_THREADS) && defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && \
+ defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
int canlog = tracking && strcmp(filename, "logger.c");
}
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+#if defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
t->track = NULL;
t->flags.tracking = tracking;
t->flags.setup = 0;
return res;
}
-int __ast_rwlock_rdlock(const char *filename, int line, const char *func, ast_rwlock_t *t, const char *name)
+int __ast_rwlock_rdlock(const char *filename, int line, const char *func,
+ ast_rwlock_t *t, const char *name)
{
int res;
+#if defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
+ int canlog = t->flags.tracking && strcmp(filename, "logger.c");
+#endif
+
#ifdef DEBUG_THREADS
struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
- int canlog = t->flags.tracking && strcmp(filename, "logger.c");
struct ast_bt *bt = NULL;
if (lt) {
}
#endif /* DEBUG_THREADS */
-#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
+#if defined(DETECT_DEADLOCKS)
{
time_t seconds = time(NULL);
time_t wait_time, reported_wait = 0;
if (wait_time > reported_wait && (wait_time % 5) == 0) {
log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
filename, line, func, (int)wait_time, name);
+#ifdef DEBUG_THREADS
if (lt) {
ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
#endif
ast_reentrancy_unlock(lt);
}
+#endif
reported_wait = wait_time;
}
usleep(200);
}
} while (res == EBUSY);
}
-#else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
+#else /* !DETECT_DEADLOCKS */
res = pthread_rwlock_rdlock(&t->lock);
-#endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
+#endif /* !DETECT_DEADLOCKS */
#ifdef DEBUG_THREADS
if (!res && lt) {
return res;
}
-int __ast_rwlock_wrlock(const char *filename, int line, const char *func, ast_rwlock_t *t, const char *name)
+int __ast_rwlock_wrlock(const char *filename, int line, const char *func, \
+ ast_rwlock_t *t, const char *name)
{
int res;
+#if defined(DEBUG_THREADS) || defined(DETECT_DEADLOCKS)
+ int canlog = t->flags.tracking && strcmp(filename, "logger.c");
+#endif
+
#ifdef DEBUG_THREADS
struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
- int canlog = t->flags.tracking && strcmp(filename, "logger.c");
struct ast_bt *bt = NULL;
if (lt) {
}
#endif /* DEBUG_THREADS */
-#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
+#ifdef DETECT_DEADLOCKS
{
time_t seconds = time(NULL);
time_t wait_time, reported_wait = 0;
if (wait_time > reported_wait && (wait_time % 5) == 0) {
log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
filename, line, func, (int)wait_time, name);
+#ifdef DEBUG_THREADS
if (lt) {
ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
#endif
ast_reentrancy_unlock(lt);
}
+#endif
reported_wait = wait_time;
}
usleep(200);
}
} while (res == EBUSY);
}
-#else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
+#else /* !DETECT_DEADLOCKS */
res = pthread_rwlock_wrlock(&t->lock);
-#endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
+#endif /* !DETECT_DEADLOCKS */
#ifdef DEBUG_THREADS
if (!res && lt) {