[asterisk-commits] qwell: branch qwell/compiler-flag-abi r247031 - in /team/qwell/compiler-flag-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 16 16:06:11 CST 2010


Author: qwell
Date: Tue Feb 16 16:06:07 2010
New Revision: 247031

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247031
Log:
Initial conceptual stab.  More to do, obviously.

Modified:
    team/qwell/compiler-flag-abi/include/asterisk/astobj2.h
    team/qwell/compiler-flag-abi/include/asterisk/lock.h
    team/qwell/compiler-flag-abi/main/astobj2.c
    team/qwell/compiler-flag-abi/main/channel.c

Modified: team/qwell/compiler-flag-abi/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/compiler-flag-abi/include/asterisk/astobj2.h?view=diff&rev=247031&r1=247030&r2=247031
==============================================================================
--- team/qwell/compiler-flag-abi/include/asterisk/astobj2.h (original)
+++ team/qwell/compiler-flag-abi/include/asterisk/astobj2.h Tue Feb 16 16:06:07 2010
@@ -185,19 +185,11 @@
  * \param a A pointer to the object we want lock.
  * \return 0 on success, other values on error.
  */
-#ifndef DEBUG_THREADS
-int ao2_lock(void *a);
-#else
+int __ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
 #define ao2_lock(a) __ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
-int __ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
-#endif
-
-#ifndef DEBUG_THREADS
-int ao2_trylock(void *a);
-#else
+
+int __ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
 #define ao2_trylock(a) __ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
-int __ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
-#endif
 
 /*!
  * Unlock an object.
@@ -205,12 +197,8 @@
  * \param a A pointer to the object we want unlock.
  * \return 0 on success, other values on error.
  */
-#ifndef DEBUG_THREADS
-int ao2_unlock(void *a);
-#else
+int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
 #define ao2_unlock(a) __ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
-int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
-#endif
 
 /*!
  *

Modified: team/qwell/compiler-flag-abi/include/asterisk/lock.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/compiler-flag-abi/include/asterisk/lock.h?view=diff&rev=247031&r1=247030&r2=247031
==============================================================================
--- team/qwell/compiler-flag-abi/include/asterisk/lock.h (original)
+++ team/qwell/compiler-flag-abi/include/asterisk/lock.h Tue Feb 16 16:06:07 2010
@@ -56,25 +56,6 @@
 #endif
 #include "asterisk/logger.h"
 
-/* internal macro to profile mutexes. Only computes the delay on
- * non-blocking calls.
- */
-#ifndef	HAVE_MTX_PROFILE
-#define	__MTX_PROF(a)	return pthread_mutex_lock((a))
-#else
-#define	__MTX_PROF(a)	do {			\
-	int i;					\
-	/* profile only non-blocking events */	\
-	ast_mark(mtx_prof, 1);			\
-	i = pthread_mutex_trylock((a));		\
-	ast_mark(mtx_prof, 0);			\
-	if (!i)					\
-		return i;			\
-	else					\
-		return pthread_mutex_lock((a)); \
-	} while (0)
-#endif	/* HAVE_MTX_PROFILE */
-
 #define AST_PTHREADT_NULL (pthread_t) -1
 #define AST_PTHREADT_STOP (pthread_t) -2
 
@@ -91,6 +72,21 @@
 #define PTHREAD_MUTEX_INIT_VALUE	PTHREAD_MUTEX_INITIALIZER
 #define AST_MUTEX_KIND			PTHREAD_MUTEX_RECURSIVE
 #endif /* PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */
+
+#define ast_mutex_destroy(a) __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
+#define ast_mutex_lock(a) __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
+#define ast_mutex_unlock(a) __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
+#define ast_mutex_trylock(a) __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
+#define ast_cond_init(cond, attr) __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
+#define ast_cond_destroy(cond) __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
+#define ast_cond_signal(cond) __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
+#define ast_cond_broadcast(cond) __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
+#define ast_cond_wait(cond, mutex) __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
+#define ast_cond_timedwait(cond, mutex, time) __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
+
+typedef struct ast_mutex_info ast_mutex_t;
+
+typedef pthread_cond_t ast_cond_t;
 
 #ifdef DEBUG_THREADS
 
@@ -123,10 +119,6 @@
 	pthread_t thread[AST_MAX_REENTRANCY];
 	pthread_mutex_t reentr_mutex;
 };
-
-typedef struct ast_mutex_info ast_mutex_t;
-
-typedef pthread_cond_t ast_cond_t;
 
 static pthread_mutex_t empty_mutex;
 
@@ -254,14 +246,31 @@
 	pthread_mutex_destroy(&p_ast_mutex->reentr_mutex);
 }
 
+#else /* !DEBUG_THREADS */
+
+#define	DEADLOCK_AVOIDANCE(lock) \
+	ast_mutex_unlock(lock); \
+	usleep(1); \
+	ast_mutex_lock(lock);
+
+
+#define AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE }
+#define AST_MUTEX_INIT_VALUE_NOTRACKING \
+                             { PTHREAD_MUTEX_INIT_VALUE }
+
+struct ast_mutex_info {
+	pthread_mutex_t mutex;
+};
+#endif /* !DEBUG_THREADS */
+
 static inline int __ast_pthread_mutex_init(int track, const char *filename, int lineno, const char *func,
 						const char *mutex_name, ast_mutex_t *t) 
 {
 	int res;
 	pthread_mutexattr_t  attr;
 
-#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-
+#ifdef DEBUG_THREADS
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
 /*
 		int canlog = strcmp(filename, "logger.c") & track;
@@ -271,11 +280,11 @@
 */
 		return 0;
 	}
-
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_reentrancy_init(t);
 	t->track = track;
+#endif /* DEBUG_THREADS */
 
 	pthread_mutexattr_init(&attr);
 	pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
@@ -294,6 +303,8 @@
 						const char *mutex_name, ast_mutex_t *t)
 {
 	int res;
+
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
@@ -328,8 +339,12 @@
 		ast_reentrancy_unlock(t);
 		break;
 	}
-
-	if ((res = pthread_mutex_destroy(&t->mutex)))
+#endif /* DEBUG_THREADS */
+
+	res = pthread_mutex_destroy(&t->mutex);
+
+#ifdef DEBUG_THREADS
+	if (res)
 		__ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
 				   filename, lineno, func, mutex_name, strerror(res));
 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
@@ -344,6 +359,7 @@
 	t->thread[0] = 0;
 	ast_reentrancy_unlock(t);
 	delete_reentrancy_cs(t);
+#endif /* DEBUG_THREADS */
 
 	return res;
 }
@@ -352,8 +368,8 @@
                                            const char* mutex_name, ast_mutex_t *t)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
-
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
 		/* Don't warn abount uninitialized mutex.
@@ -371,17 +387,19 @@
 
 	if (t->track)
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
+#endif /* DEBUG_THREADS */
 
 #ifdef DETECT_DEADLOCKS
+#ifdef DEBUG_THREADS
 	{
 		time_t seconds = time(NULL);
 		time_t wait_time, reported_wait = 0;
 		do {
-#ifdef	HAVE_MTX_PROFILE
+#ifdef HAVE_MTX_PROFILE
 			ast_mark(mtx_prof, 1);
 #endif
 			res = pthread_mutex_trylock(&t->mutex);
-#ifdef	HAVE_MTX_PROFILE
+#ifdef HAVE_MTX_PROFILE
 			ast_mark(mtx_prof, 0);
 #endif
 			if (res == EBUSY) {
@@ -400,16 +418,18 @@
 			}
 		} while (res == EBUSY);
 	}
-#else
-#ifdef	HAVE_MTX_PROFILE
+#endif /* DEBUG_THREADS */
+#else /* !DETECT_DEADLOCKS */
+#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 */
-
+#endif /* !DETECT_DEADLOCKS */
+
+#ifdef DEBUG_THREADS
 	if (!res) {
 		ast_reentrancy_lock(t);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
@@ -432,7 +452,7 @@
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
 	}
-
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -440,6 +460,7 @@
                                               const char* mutex_name, ast_mutex_t *t)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
@@ -459,8 +480,12 @@
 
 	if (t->track)
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
-
-	if (!(res = pthread_mutex_trylock(&t->mutex))) {
+#endif /* DEBUG_THREADS */
+
+	res = pthread_mutex_trylock(&t->mutex);
+
+#ifdef DEBUG_THREADS
+	if (!res) {
 		ast_reentrancy_lock(t);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
@@ -478,7 +503,7 @@
 	} else if (t->track) {
 		ast_mark_lock_failed(&t->mutex);
 	}
-
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -486,6 +511,7 @@
 					     const char *mutex_name, ast_mutex_t *t)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
@@ -526,13 +552,17 @@
 
 	if (t->track)
 		ast_remove_lock_info(&t->mutex);
-
-	if ((res = pthread_mutex_unlock(&t->mutex))) {
+#endif /* DEBUG_THREADS */
+
+	res = pthread_mutex_unlock(&t->mutex);
+
+#ifdef DEBUG_THREADS
+	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n", 
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
 	}
-
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -565,6 +595,7 @@
 				  ast_cond_t *cond, ast_mutex_t *t)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
@@ -605,8 +636,12 @@
 
 	if (t->track)
 		ast_remove_lock_info(&t->mutex);
-
-	if ((res = pthread_cond_wait(cond, &t->mutex))) {
+#endif /* DEBUG_THREADS */
+
+	res = pthread_cond_wait(cond, &t->mutex);
+
+#ifdef DEBUG_THREADS
+	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n", 
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
@@ -627,7 +662,7 @@
 		if (t->track)
 			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 	}
-
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -636,6 +671,7 @@
 				       ast_mutex_t *t, const struct timespec *abstime)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
@@ -676,8 +712,12 @@
 
 	if (t->track)
 		ast_remove_lock_info(&t->mutex);
-
-	if ((res = pthread_cond_timedwait(cond, &t->mutex, abstime)) && (res != ETIMEDOUT)) {
+#endif /* DEBUG_THREADS */
+
+	res = pthread_cond_timedwait(cond, &t->mutex, abstime);
+
+#ifdef DEBUG_THREADS
+	if (res && (res != ETIMEDOUT)) {
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n", 
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
@@ -698,105 +738,9 @@
 		if (t->track)
 			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 	}
-
-	return res;
-}
-
-#define ast_mutex_destroy(a) __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_lock(a) __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_unlock(a) __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_mutex_trylock(a) __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
-#define ast_cond_init(cond, attr) __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
-#define ast_cond_destroy(cond) __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_signal(cond) __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_broadcast(cond) __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
-#define ast_cond_wait(cond, mutex) __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
-#define ast_cond_timedwait(cond, mutex, time) __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
-
-#else /* !DEBUG_THREADS */
-
-#define	DEADLOCK_AVOIDANCE(lock) \
-	ast_mutex_unlock(lock); \
-	usleep(1); \
-	ast_mutex_lock(lock);
-
-
-typedef pthread_mutex_t ast_mutex_t;
-
-#define AST_MUTEX_INIT_VALUE	((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
-#define AST_MUTEX_INIT_VALUE_NOTRACKING \
-	((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
-
-#define ast_mutex_init_notracking(m) ast_mutex_init(m)
-
-static inline int ast_mutex_init(ast_mutex_t *pmutex)
-{
-	int res;
-	pthread_mutexattr_t attr;
-
-	pthread_mutexattr_init(&attr);
-	pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
-
-	res = pthread_mutex_init(pmutex, &attr);
-	pthread_mutexattr_destroy(&attr);
-	return res;
-}
-
-#define ast_pthread_mutex_init(pmutex,a) pthread_mutex_init(pmutex,a)
-
-static inline int ast_mutex_unlock(ast_mutex_t *pmutex)
-{
-	return pthread_mutex_unlock(pmutex);
-}
-
-static inline int ast_mutex_destroy(ast_mutex_t *pmutex)
-{
-	return pthread_mutex_destroy(pmutex);
-}
-
-static inline int ast_mutex_lock(ast_mutex_t *pmutex)
-{
-	__MTX_PROF(pmutex);
-}
-
-static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
-{
-	return pthread_mutex_trylock(pmutex);
-}
-
-typedef pthread_cond_t ast_cond_t;
-
-static inline int ast_cond_init(ast_cond_t *cond, pthread_condattr_t *cond_attr)
-{
-	return pthread_cond_init(cond, cond_attr);
-}
-
-static inline int ast_cond_signal(ast_cond_t *cond)
-{
-	return pthread_cond_signal(cond);
-}
-
-static inline int ast_cond_broadcast(ast_cond_t *cond)
-{
-	return pthread_cond_broadcast(cond);
-}
-
-static inline int ast_cond_destroy(ast_cond_t *cond)
-{
-	return pthread_cond_destroy(cond);
-}
-
-static inline int ast_cond_wait(ast_cond_t *cond, ast_mutex_t *t)
-{
-	return pthread_cond_wait(cond, t);
-}
-
-static inline int ast_cond_timedwait(ast_cond_t *cond, ast_mutex_t *t, const struct timespec *abstime)
-{
-	return pthread_cond_timedwait(cond, t, abstime);
-}
-
-#endif /* !DEBUG_THREADS */
+#endif /* DEBUG_THREADS */
+	return res;
+}
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 /* If AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope
@@ -853,15 +797,13 @@
 #define AST_RWLOCK_INIT_VALUE NULL
 #endif
 
-#ifdef DEBUG_THREADS
-
 #define ast_rwlock_init(rwlock) __ast_rwlock_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 
-
 static inline int __ast_rwlock_init(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock)
 {
 	int res;
 	pthread_rwlockattr_t attr;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
         int canlog = strcmp(filename, "logger.c");
 
@@ -871,6 +813,7 @@
 		return 0;
 	}
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+#endif /* DEBUG_THREADS */
 	pthread_rwlockattr_init(&attr);
 
 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
@@ -887,6 +830,7 @@
 static inline int __ast_rwlock_destroy(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock)
 {
 	int res;
+#ifdef DEBUG_THREADS
 	int canlog = strcmp(filename, "logger.c");
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
@@ -896,10 +840,16 @@
 		return 0;
 	}
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
-	
-	if ((res = pthread_rwlock_destroy(prwlock)))
+#endif /* DEBUG_THREADS */
+
+	res = pthread_rwlock_destroy(prwlock);
+
+#ifdef DEBUG_THREADS
+	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
 				filename, lineno, func, rwlock_name, strerror(res));
+	}
+#endif /* DEBUG_THREADS */
 
 	return res;
 }
@@ -911,6 +861,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 
@@ -925,9 +876,13 @@
 		return res;
 	}
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+#endif /* DEBUG_THREADS */
 	
 	res = pthread_rwlock_unlock(lock);
+
+#ifdef DEBUG_THREADS
 	ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -938,6 +893,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -956,11 +912,16 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 	
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 	res = pthread_rwlock_rdlock(lock);
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
 	return res;
 }
 
@@ -971,6 +932,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -989,11 +951,17 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 	res = pthread_rwlock_wrlock(lock);
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
+
 	return res;
 }
 
@@ -1004,6 +972,7 @@
 	const struct timespec *abs_timeout, const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -1022,6 +991,8 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 	
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
 	res = pthread_rwlock_timedrdlock(lock, abs_timeout);
 #else
@@ -1039,10 +1010,14 @@
 		}
 	} while (0);
 #endif
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
+
 	return res;
 }
 
@@ -1053,6 +1028,7 @@
 	const struct timespec *abs_timeout, const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -1071,6 +1047,8 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
 	res = pthread_rwlock_timedwrlock(lock, abs_timeout);
 #else
@@ -1088,10 +1066,14 @@
 		}
 	} while (0);
 #endif
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
+
 	return res;
 }
 
@@ -1102,6 +1084,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -1120,11 +1103,17 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 	res = pthread_rwlock_tryrdlock(lock);
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
+#endif /* DEBUG_THREADS */
+
 	return res;
 }
 
@@ -1135,6 +1124,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef DEBUG_THREADS
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(file, "logger.c");
 	
@@ -1153,106 +1143,19 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
+#endif /* DEBUG_THREADS */
+
 	res = pthread_rwlock_trywrlock(lock);
+
+#ifdef DEBUG_THREADS
 	if (!res)
 		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
-	return res;
-}
-
-#else /* !DEBUG_THREADS */
-
-static inline int ast_rwlock_init(ast_rwlock_t *prwlock)
-{
-	int res;
-	pthread_rwlockattr_t attr;
-
-	pthread_rwlockattr_init(&attr);
-
-#ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
-	pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
-#endif
-
-	res = pthread_rwlock_init(prwlock, &attr);
-	pthread_rwlockattr_destroy(&attr);
-	return res;
-}
-
-static inline int ast_rwlock_destroy(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_destroy(prwlock);
-}
-
-static inline int ast_rwlock_unlock(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_unlock(prwlock);
-}
-
-static inline int ast_rwlock_rdlock(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_rdlock(prwlock);
-}
-
-static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
-{
-	int res;
-#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
-	res = pthread_rwlock_timedrdlock(prwlock, abs_timeout);
-#else
-	struct timeval _start = ast_tvnow(), _diff;
-	for (;;) {
-		if (!(res = pthread_rwlock_tryrdlock(prwlock))) {
-			break;
-		}
-		_diff = ast_tvsub(ast_tvnow(), _start);
-		if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
-			break;
-		}
-		usleep(1);
-	}
-#endif
-	return res;
-}
-
-static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_tryrdlock(prwlock);
-}
-
-static inline int ast_rwlock_wrlock(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_wrlock(prwlock);
-}
-
-static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
-{
-	int res;
-#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
-	res = pthread_rwlock_timedwrlock(prwlock, abs_timeout);
-#else
-	do {
-		struct timeval _start = ast_tvnow(), _diff;
-		for (;;) {
-			if (!(res = pthread_rwlock_trywrlock(prwlock))) {
-				break;
-			}
-			_diff = ast_tvsub(ast_tvnow(), _start);
-			if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
-				break;
-			}
-			usleep(1);
-		}
-	} while (0);
-#endif
-	return res;
-}
-
-static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock)
-{
-	return pthread_rwlock_trywrlock(prwlock);
-}
-#endif /* !DEBUG_THREADS */
+#endif /* DEBUG_THREADS */
+
+	return res;
+}
 
 /* Statically declared read/write locks */
 
@@ -1365,35 +1268,21 @@
 })
 #endif
 
-#ifndef DEBUG_CHANNEL_LOCKS
-/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined 
-	in the Makefile, print relevant output for debugging */
-#define ast_channel_lock(x)		ast_mutex_lock(&x->lock)
-/*! \brief Unlock a channel. If DEBUG_CHANNEL_LOCKS is defined 
-	in the Makefile, print relevant output for debugging */
-#define ast_channel_unlock(x)		ast_mutex_unlock(&x->lock)
-/*! \brief Try locking a channel. If DEBUG_CHANNEL_LOCKS is defined 
-	in the Makefile, print relevant output for debugging */
-#define ast_channel_trylock(x)		ast_mutex_trylock(&x->lock)
-#else
-
 struct ast_channel;
 
 #define ast_channel_lock(a) __ast_channel_lock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Lock AST channel (and print debugging output)
-\note You need to enable DEBUG_CHANNEL_LOCKS for this function */
+\note You need to enable DEBUG_CHANNEL_LOCKS for debugging output */
 int __ast_channel_lock(struct ast_channel *chan, const char *file, int lineno, const char *func);
 
 #define ast_channel_unlock(a) __ast_channel_unlock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Unlock AST channel (and print debugging output)
-\note You need to enable DEBUG_CHANNEL_LOCKS for this function
-*/
+\note You need to enable DEBUG_CHANNEL_LOCKS for debugging output */
 int __ast_channel_unlock(struct ast_channel *chan, const char *file, int lineno, const char *func);
 
 #define ast_channel_trylock(a) __ast_channel_trylock(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 /*! \brief Lock AST channel (and print debugging output)
-\note   You need to enable DEBUG_CHANNEL_LOCKS for this function */
+\note You need to enable DEBUG_CHANNEL_LOCKS for debugging output */
 int __ast_channel_trylock(struct ast_channel *chan, const char *file, int lineno, const char *func);
-#endif
 
 #endif /* _ASTERISK_LOCK_H */

Modified: team/qwell/compiler-flag-abi/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/compiler-flag-abi/main/astobj2.c?view=diff&rev=247031&r1=247030&r2=247031
==============================================================================
--- team/qwell/compiler-flag-abi/main/astobj2.c (original)
+++ team/qwell/compiler-flag-abi/main/astobj2.c Tue Feb 16 16:06:07 2010
@@ -125,11 +125,7 @@
  */
 #define EXTERNAL_OBJ(_p)	((_p) == NULL ? NULL : (_p)->user_data)
 
-#ifndef DEBUG_THREADS
-int ao2_lock(void *user_data)
-#else
 int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 
@@ -140,18 +136,10 @@
 	ast_atomic_fetchadd_int(&ao2.total_locked, 1);
 #endif
 
-#ifndef DEBUG_THREADS
-	return ast_mutex_lock(&p->priv_data.lock);
-#else
 	return __ast_pthread_mutex_lock(file, line, func, var, &p->priv_data.lock);
-#endif
-}
-
-#ifndef DEBUG_THREADS
-int ao2_trylock(void *user_data)
-#else
+}
+
 int __ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 	int res;
@@ -159,11 +147,7 @@
 	if (p == NULL)
 		return -1;
 
-#ifndef DEBUG_THREADS
-	res = ast_mutex_trylock(&p->priv_data.lock);
-#else
 	res = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock);
-#endif
 
 #ifdef AO2_DEBUG
 	if (!res) {
@@ -174,11 +158,7 @@
 	return res;
 }
 
-#ifndef DEBUG_THREADS
-int ao2_unlock(void *user_data)
-#else
 int __ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 
@@ -189,11 +169,7 @@
 	ast_atomic_fetchadd_int(&ao2.total_locked, -1);
 #endif
 
-#ifndef DEBUG_THREADS
-	return ast_mutex_unlock(&p->priv_data.lock);
-#else
 	return __ast_pthread_mutex_unlock(file, line, func, var, &p->priv_data.lock);
-#endif
 }
 
 /*

Modified: team/qwell/compiler-flag-abi/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/compiler-flag-abi/main/channel.c?view=diff&rev=247031&r1=247030&r2=247031
==============================================================================
--- team/qwell/compiler-flag-abi/main/channel.c (original)
+++ team/qwell/compiler-flag-abi/main/channel.c Tue Feb 16 16:06:07 2010
@@ -5059,14 +5059,14 @@
 	}
 };
 
+
+/*! \brief Unlock AST channel (and print debugging output) 
+\note You need to enable DEBUG_CHANNEL_LOCKS for the debugging output */
+int __ast_channel_unlock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
+{
+	int res = 0;
+
 #ifdef DEBUG_CHANNEL_LOCKS
-
-/*! \brief Unlock AST channel (and print debugging output) 
-\note You need to enable DEBUG_CHANNEL_LOCKS for this function
-*/
-int __ast_channel_unlock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
-{
-	int res = 0;
 	if (option_debug > 2) 
 		ast_log(LOG_DEBUG, "::::==== Unlocking AST channel %s\n", chan->name);
 	
@@ -5075,12 +5075,11 @@
 			ast_log(LOG_DEBUG, "::::==== Unlocking non-existing channel \n");
 		return 0;
 	}
-#ifdef DEBUG_THREADS
+#endif
+
 	res = __ast_pthread_mutex_unlock(filename, lineno, func, "(channel lock)", &chan->lock);
-#else
-	res = ast_mutex_unlock(&chan->lock);
-#endif
-
+
+#ifdef DEBUG_CHANNEL_LOCKS
 	if (option_debug > 2) {
 #ifdef DEBUG_THREADS
 		int count = 0;
@@ -5093,30 +5092,32 @@
 			ast_log(LOG_DEBUG, "::::==== Channel %s had no lock by this thread. Failed unlocking\n", chan->name);
 		}
 	}
+#endif
 	if (res == EPERM) {
 		/* We had no lock, so okay any way*/
+#ifdef DEBUG_CHANNEL_LOCKS
 		if (option_debug > 3)
 			ast_log(LOG_DEBUG, "::::==== Channel %s was not locked at all \n", chan->name);
+#endif
 		res = 0;
 	}
 	return res;
 }
 
 /*! \brief Lock AST channel (and print debugging output)
-\note You need to enable DEBUG_CHANNEL_LOCKS for this function */
+\note You need to enable DEBUG_CHANNEL_LOCKS for the debugging output */
 int __ast_channel_lock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
 {
 	int res;
 
+#ifdef DEBUG_CHANNEL_LOCKS
 	if (option_debug > 3)
 		ast_log(LOG_DEBUG, "====:::: Locking AST channel %s\n", chan->name);
-
-#ifdef DEBUG_THREADS
+#endif
+
 	res = __ast_pthread_mutex_lock(filename, lineno, func, "(channel lock)", &chan->lock);
-#else
-	res = ast_mutex_lock(&chan->lock);
-#endif
-
+
+#ifdef DEBUG_CHANNEL_LOCKS
 	if (option_debug > 3) {
 #ifdef DEBUG_THREADS
 		int count = 0;
@@ -5133,23 +5134,24 @@
 			ast_log(LOG_DEBUG, "::::==== Channel %s lock failed. No mutex.\n", chan->name);
 		}
 	}
+#endif
 	return res;
 }
 
 /*! \brief Lock AST channel (and print debugging output)
-\note	You need to enable DEBUG_CHANNEL_LOCKS for this function */
+\note You need to enable DEBUG_CHANNEL_LOCKS for the debugging output */
 int __ast_channel_trylock(struct ast_channel *chan, const char *filename, int lineno, const char *func)
 {
 	int res;
 
+#ifdef DEBUG_CHANNEL_LOCKS
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "====:::: Trying to lock AST channel %s\n", chan->name);
-#ifdef DEBUG_THREADS
+#endif
+
 	res = __ast_pthread_mutex_trylock(filename, lineno, func, "(channel lock)", &chan->lock);
-#else
-	res = ast_mutex_trylock(&chan->lock);
-#endif
-
+
+#ifdef DEBUG_CHANNEL_LOCKS
 	if (option_debug > 2) {
 #ifdef DEBUG_THREADS
 		int count = 0;
@@ -5169,10 +5171,9 @@
 		if (res == EINVAL)
 			ast_log(LOG_DEBUG, "::::==== Channel %s lock failed. No mutex.\n", chan->name);
 	}
+#endif
 	return res;
 }
-
-#endif
 
 /*
  * Wrappers for various ast_say_*() functions that call the full version




More information about the asterisk-commits mailing list