[Python-checkins] cpython: Signal condition variables with the mutex held. Destroy condition variables
kristjan.jonsson
python-checkins at python.org
Wed Jun 6 00:18:42 CEST 2012
http://hg.python.org/cpython/rev/6d146e2ae9a9
changeset: 77365:6d146e2ae9a9
user: Kristján Valur Jónsson <kristjan at ccpgames.com>
date: Tue Jun 05 22:17:42 2012 +0000
summary:
Signal condition variables with the mutex held. Destroy condition variables
before their mutexes.
files:
Python/ceval_gil.h | 9 +++++----
Python/thread_pthread.h | 15 +++++++++------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h
--- a/Python/ceval_gil.h
+++ b/Python/ceval_gil.h
@@ -313,14 +313,15 @@
static void destroy_gil(void)
{
+ /* some pthread-like implementations tie the mutex to the cond
+ * and must have the cond destroyed first.
+ */
+ COND_FINI(gil_cond);
MUTEX_FINI(gil_mutex);
#ifdef FORCE_SWITCHING
+ COND_FINI(switch_cond);
MUTEX_FINI(switch_mutex);
#endif
- COND_FINI(gil_cond);
-#ifdef FORCE_SWITCHING
- COND_FINI(switch_cond);
-#endif
_Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release);
_Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked);
}
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -443,12 +443,15 @@
dprintf(("PyThread_free_lock(%p) called\n", lock));
+ /* some pthread-like implementations tie the mutex to the cond
+ * and must have the cond destroyed first.
+ */
+ status = pthread_cond_destroy( &thelock->lock_released );
+ CHECK_STATUS("pthread_cond_destroy");
+
status = pthread_mutex_destroy( &thelock->mut );
CHECK_STATUS("pthread_mutex_destroy");
- status = pthread_cond_destroy( &thelock->lock_released );
- CHECK_STATUS("pthread_cond_destroy");
-
free((void *)thelock);
}
@@ -531,12 +534,12 @@
thelock->locked = 0;
- status = pthread_mutex_unlock( &thelock->mut );
- CHECK_STATUS("pthread_mutex_unlock[3]");
-
/* wake up someone (anyone, if any) waiting on the lock */
status = pthread_cond_signal( &thelock->lock_released );
CHECK_STATUS("pthread_cond_signal");
+
+ status = pthread_mutex_unlock( &thelock->mut );
+ CHECK_STATUS("pthread_mutex_unlock[3]");
}
#endif /* USE_SEMAPHORES */
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list