summaryrefslogtreecommitdiff
path: root/include/asterisk/lock.h
diff options
context:
space:
mode:
authorLuigi Rizzo <rizzo@icir.org>2006-04-12 20:40:46 +0000
committerLuigi Rizzo <rizzo@icir.org>2006-04-12 20:40:46 +0000
commit2876a25505894c70ffc35fb35ab517a53912780f (patch)
tree0b296463204ccd97d57e585d6659dd75d15280fc /include/asterisk/lock.h
parent8f09c4345feb6035621c2336d4adbc55858f2e13 (diff)
add 'show threads' and 'show profile' commands.
These are momstly debugging tools for developers, a bit documented in the header files (utils.h), although more documentation is definitely necessary. The performance impact is close to zero(*) so there is no need to compile it conditionally. (*) not completely true - thread destruction still needs to search a list _but_ this can be easily optimized if we end up with hundreds of active threads (in which case, though, the problem is clearly elsewhere). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@19544 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/lock.h')
-rw-r--r--include/asterisk/lock.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index f0192e7ba..e86462306 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -56,6 +56,23 @@
#ifndef _ASTERISK_LOCK_H
#define _ASTERISK_LOCK_H
+/* internal macro to profile mutexes. Only computes the delay on
+ * non-blocking calls.
+ */
+#ifndef HAVE_MTX_PROFILE
+#define __MTX_PROF /* nothing */
+#else
+#define __MTX_PROF { \
+ int i; \
+ /* profile only non-blocking events */ \
+ ast_mark(mtx_prof, 1); \
+ i = pthread_mutex_trylock(pmutex); \
+ ast_mark(mtx_prof, 0); \
+ if (!i) \
+ return i; \
+ }
+#endif /* HAVE_MTX_PROFILE */
+
#include <pthread.h>
#include <netdb.h>
#include <time.h>
@@ -75,7 +92,7 @@
#endif
#ifdef BSD
-#ifdef __GNUC__
+#if 0 && defined( __GNUC__)
#define AST_MUTEX_INIT_W_CONSTRUCTORS
#else
#define AST_MUTEX_INIT_ON_FIRST_USE
@@ -264,7 +281,13 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
time_t seconds = time(NULL);
time_t current;
do {
+#ifdef HAVE_MTX_PROFILE
+ ast_mark(mtx_prof, 1);
+#endif
res = pthread_mutex_trylock(&t->mutex);
+#ifdef HAVE_MTX_PROFILE
+ ast_mark(mtx_prof, 0);
+#endif
if (res == EBUSY) {
current = time(NULL);
if ((current - seconds) && (!((current - seconds) % 5))) {
@@ -279,6 +302,12 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
} while (res == EBUSY);
}
#else
+#ifdef HAVE_MTX_PROFILE
+ ast_mark(mtx_prof, 1);
+ res = pthread_mutex_trylock(&t->mutex);
+ ast_mark(mtx_prof, 0);
+ if (res)
+#endif
res = pthread_mutex_lock(&t->mutex);
#endif /* DETECT_DEADLOCKS */
@@ -581,6 +610,7 @@ static void __attribute__ ((destructor)) fini_##mutex(void) \
static inline int ast_mutex_lock(ast_mutex_t *pmutex)
{
+ __MTX_PROF
return pthread_mutex_lock(pmutex);
}
@@ -601,8 +631,10 @@ static inline int ast_mutex_lock(ast_mutex_t *pmutex)
{
if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
ast_mutex_init(pmutex);
+ __MTX_PROF
return pthread_mutex_lock(pmutex);
}
+
static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
{
if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
@@ -616,6 +648,7 @@ static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
static inline int ast_mutex_lock(ast_mutex_t *pmutex)
{
+ __MTX_PROF
return pthread_mutex_lock(pmutex);
}