Index: include/asterisk/lock.h
===================================================================
--- include/asterisk/lock.h	(revision 89084)
+++ include/asterisk/lock.h	(working copy)
@@ -74,9 +74,9 @@
 #define AST_PTHREADT_NULL (pthread_t) -1
 #define AST_PTHREADT_STOP (pthread_t) -2
 
-#if defined(SOLARIS) || defined(BSD)
-#define AST_MUTEX_INIT_W_CONSTRUCTORS
-#endif /* SOLARIS || BSD */
+#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 
+#define AST_MUTEX_INIT_W_CONSTRUCTORS 
+#endif /* NetBSD, OpenBSD, FreeBSD */
 
 /* Asterisk REQUIRES recursive (not error checking) mutexes
    and will not run without them. */
@@ -125,7 +125,8 @@
 
 typedef pthread_cond_t ast_cond_t;
 
-static pthread_mutex_t empty_mutex;
+/* uninitialized static mutex, used for testing purpose */
+static pthread_mutex_t empty_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 enum ast_lock_type {
 	AST_MUTEX,
@@ -162,10 +163,6 @@
  */
 void ast_remove_lock_info(void *lock_addr);
 
-static void __attribute__((constructor)) init_empty_mutex(void)
-{
-	memset(&empty_mutex, 0, sizeof(empty_mutex));
-}
 
 static inline void ast_reentrancy_lock(ast_mutex_t *p_ast_mutex)
 {
@@ -209,14 +206,11 @@
 	static pthread_mutexattr_t  attr;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-
-	if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
-/*
+	if (memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
 		int canlog = strcmp(filename, "logger.c") & track;
 		__ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
 				   filename, lineno, func, mutex_name);
 		DO_THREAD_CRASH;
-*/
 		return 0;
 	}
 
@@ -244,12 +238,10 @@
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
 		/* Don't try to uninitialize non initialized mutex
 		 * This may no effect on linux
-		 * And always ganerate core on *BSD with 
-		 * linked libpthread
-		 * This not error condition if the mutex created on the fly.
+		 * And always ganerate core on FreeBSD with linked libpthread
 		 */
 		__ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
 				   filename, lineno, func, mutex_name);
@@ -302,11 +294,10 @@
 	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.
-		 * Simple try to initialize it.
-		 * May be not needed in linux system.
-		 */
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
+		__ast_mutex_logger("%s line %d (%s): Error: lock uninitialized mutex '%s'.\n",
+			filename, lineno, func, mutex_name);
+
 		res = __ast_pthread_mutex_init(t->track, filename, lineno, func, mutex_name, t);
 		if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
 			__ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
@@ -389,11 +380,10 @@
 	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.
-		 * Simple try to initialize it.
-		 * May be not needed in linux system.
-		 */
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
+		__ast_mutex_logger("%s line %d (%s): Error: trylock uninitialized mutex '%s'.\n",
+			filename, lineno, func, mutex_name);
+
 		res = __ast_pthread_mutex_init(t->track, filename, lineno, func, mutex_name, t);
 		if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
 			__ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
@@ -435,8 +425,8 @@
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
-		__ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
+		__ast_mutex_logger("%s line %d (%s): Error: unlock uninitialized mutex '%s'.\n",
 				   filename, lineno, func, mutex_name);
 		res = __ast_pthread_mutex_init(t->track, filename, lineno, func, mutex_name, t);
 		if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -514,7 +504,7 @@
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
 		__ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
 				   filename, lineno, func, mutex_name);
 		res = __ast_pthread_mutex_init(t->track, filename, lineno, func, mutex_name, t);
@@ -585,7 +575,7 @@
 	int canlog = strcmp(filename, "logger.c") & t->track;
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
-	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
+	if (!memcmp(&(t->mutex), &empty_mutex, sizeof(pthread_mutex_t)) ) {
 		__ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
 				   filename, lineno, func, mutex_name);
 		res = __ast_pthread_mutex_init(t->track, filename, lineno, func, mutex_name, t);
