[svn-commits] russell: branch russell/chan_console r95351 - /team/russell/chan_console/incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 28 23:47:16 CST 2007


Author: russell
Date: Fri Dec 28 23:47:16 2007
New Revision: 95351

URL: http://svn.digium.com/view/asterisk?view=rev&rev=95351
Log:
restore lock.h code ... this doesn't build on my mac, but it's broken in trunk,
too, so i'm not going to mess with it right now.

Modified:
    team/russell/chan_console/include/asterisk/lock.h

Modified: team/russell/chan_console/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/team/russell/chan_console/include/asterisk/lock.h?view=diff&rev=95351&r1=95350&r2=95351
==============================================================================
--- team/russell/chan_console/include/asterisk/lock.h (original)
+++ team/russell/chan_console/include/asterisk/lock.h Fri Dec 28 23:47:16 2007
@@ -215,6 +215,20 @@
 	int res;
 	pthread_mutexattr_t  attr;
 
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+
+	if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
+/*
+		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;
+	}
+
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+
 	ast_reentrancy_init(t);
 	t->track = track;
 
@@ -235,6 +249,20 @@
 {
 	int res;
 	int canlog = strcmp(filename, "logger.c") & t->track;
+
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
+		/* 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.
+		 */
+		__ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
+				   filename, lineno, func, mutex_name);
+		return 0;
+	}
+#endif
 
 	res = pthread_mutex_trylock(&t->mutex);
 	switch (res) {
@@ -258,7 +286,10 @@
 	if ((res = pthread_mutex_destroy(&t->mutex)))
 		__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
+	else
+		t->mutex = PTHREAD_MUTEX_INIT_VALUE;
+#endif
 	ast_reentrancy_lock(t);
 	t->file[0] = filename;
 	t->lineno[0] = lineno;
@@ -276,6 +307,21 @@
 {
 	int res;
 	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.
+		 */
+		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",
+					 filename, lineno, func, mutex_name);
+			return res;
+		}		
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	if (t->track)
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
@@ -350,6 +396,21 @@
 	int res;
 	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.
+		 */
+		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",
+					 filename, lineno, func, mutex_name);
+			return res;
+		}		
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+
 	if (t->track)
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 
@@ -381,6 +442,19 @@
 	int res;
 	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",
+				   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",
+					 filename, lineno, func, mutex_name);
+		}
+		return res;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+
 	ast_reentrancy_lock(t);
 	if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
 		__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
@@ -446,6 +520,19 @@
 {
 	int res;
 	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",
+				   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",
+					 filename, lineno, func, mutex_name);
+		}
+		return res;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_reentrancy_lock(t);
 	if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
@@ -505,6 +592,19 @@
 	int res;
 	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",
+				   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",
+					 filename, lineno, func, mutex_name);
+		}
+		return res;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+
 	ast_reentrancy_lock(t);
 	if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
 		__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
@@ -726,6 +826,15 @@
 {
 	int res;
 	pthread_rwlockattr_t attr;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+        int canlog = strcmp(filename, "logger.c");
+
+        if (*prwlock != ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		__ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
+				filename, lineno, func, rwlock_name);
+		return 0;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 	pthread_rwlockattr_init(&attr);
 
 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
@@ -743,6 +852,14 @@
 	int res;
 	int canlog = strcmp(filename, "logger.c");
 
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	if (*prwlock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		__ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
+				   filename, lineno, func, rwlock_name);
+		return 0;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+	
 	if ((res = pthread_rwlock_destroy(prwlock)))
 		__ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
 				filename, lineno, func, rwlock_name, strerror(res));
@@ -755,6 +872,21 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	int canlog = strcmp(file, "logger.c");
+
+	if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		__ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
+				   file, line, func, name);
+		res = __ast_rwlock_init(file, line, func, name, lock);
+		if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+			__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
+					file, line, func, name);
+		}
+		return res;
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
+	
 	res = pthread_rwlock_unlock(lock);
 	ast_remove_lock_info(lock);
 	return res;
@@ -765,6 +897,22 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	int canlog = strcmp(file, "logger.c");
+	
+	if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		 /* Don't warn abount uninitialized lock.
+		  * Simple try to initialize it.
+		  * May be not needed in linux system.
+		  */
+		res = __ast_rwlock_init(file, line, func, name, lock);
+		if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+			__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
+					file, line, func, name);
+			return res;
+		}
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 	
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_rdlock(lock);
@@ -780,6 +928,22 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	int canlog = strcmp(file, "logger.c");
+	
+	if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		 /* Don't warn abount uninitialized lock.
+		  * Simple try to initialize it.
+		  * May be not needed in linux system.
+		  */
+		res = __ast_rwlock_init(file, line, func, name, lock);
+		if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+			__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
+					file, line, func, name);
+			return res;
+		}
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_wrlock(lock);
@@ -795,6 +959,22 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	int canlog = strcmp(file, "logger.c");
+	
+	if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		 /* Don't warn abount uninitialized lock.
+		  * Simple try to initialize it.
+		  * May be not needed in linux system.
+		  */
+		res = __ast_rwlock_init(file, line, func, name, lock);
+		if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+			__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
+					file, line, func, name);
+			return res;
+		}
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_tryrdlock(lock);
@@ -810,6 +990,22 @@
 	const char *file, int line, const char *func)
 {
 	int res;
+#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
+	int canlog = strcmp(file, "logger.c");
+	
+	if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+		 /* Don't warn abount uninitialized lock.
+		  * Simple try to initialize it.
+		  * May be not needed in linux system.
+		  */
+		res = __ast_rwlock_init(file, line, func, name, lock);
+		if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) {
+			__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
+					file, line, func, name);
+			return res;
+		}
+	}
+#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_trywrlock(lock);




More information about the svn-commits mailing list