[xiph-commits] r13406 - experimental/moritz/thread

moritz at svn.xiph.org moritz at svn.xiph.org
Mon Jul 30 14:49:01 PDT 2007


Author: moritz
Date: 2007-07-30 14:49:01 -0700 (Mon, 30 Jul 2007)
New Revision: 13406

Modified:
   experimental/moritz/thread/thread.c
Log:
Protect the shutdown of the library.


Modified: experimental/moritz/thread/thread.c
===================================================================
--- experimental/moritz/thread/thread.c	2007-07-30 21:25:36 UTC (rev 13405)
+++ experimental/moritz/thread/thread.c	2007-07-30 21:49:01 UTC (rev 13406)
@@ -526,6 +526,13 @@
 	if (!thread_initialized)
 		_thread_fatal(0, "THREAD: thread_shutdown(): Thread library not initialized\n");
 
+	thread_initialized = 0;
+
+	_mutex_lock(threadtree_mutex);
+	_mutex_lock(mutextree_mutex);
+	_mutex_lock(condtree_mutex);
+	_mutex_lock(rwlocktree_mutex);
+
 	for (rwlock = RB_MIN(rwlock_tree, &rwlock_tree_head);
 	     rwlock != NULL;
 	     rwlock = rwlock_next) {
@@ -558,6 +565,11 @@
 		_thread_free(&thread);
 	}
 
+	_mutex_unlock(rwlocktree_mutex);
+	_mutex_unlock(condtree_mutex);
+	_mutex_unlock(mutextree_mutex);
+	_mutex_unlock(threadtree_mutex);
+
 	if ((error = pthread_mutex_destroy(&library_mutex->sys_mutex)) != 0)
 		_thread_fatal(error, "THREAD: pthread_mutex_destroy(%s)",
 			      library_mutex->name);
@@ -579,8 +591,6 @@
 			      mutextree_mutex->name);
 	_mutex_free(&mutextree_mutex);
 
-	thread_initialized = 0;
-
 	_thread_debug_printf(4, "======> SHUTDOWN thread done\n");
 }
 



More information about the commits mailing list